-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
Summary
Currently, the semantic/compile-time syntax errors are tested through a combination of inline parser tests and separate integration tests in ruff and red-knot. As suggested here, it could be good to expand the integration tests to cover all of the semantic error variants to ensure that changes to the semantic models don't affect error reporting.
The errors correspond to variants of SemanticSyntaxErrorKind, and each variant should have documentation with examples of errors. These are a great starting point for the new tests, and in some cases they might be sufficient on their own.
A great first step here would be to fill in the Status table below by identifying which variants are currently tested.
Ruff
In ruff, the current integration tests are in linter.rs. For semantic errors that correspond to existing ruff rules, more test_cases can simply be added to the test_syntax_errors function, while standalone errors will need to be handled separately. It might be best to refactor test_async_comprehension_in_sync_comprehension into a more general test function that can run these cases.
Red Knot
In red-knot, the integration mdtests are in semantic_syntax_errors.md. Each level 2 heading corresponds to a single semantic syntax error, so we just need new sections with examples for each of the missing variants.
Status
| Rule | Ruff | Red Knot |
|---|---|---|
LateFutureImport |
✅ | ✅ |
ReboundComprehensionVariable |
✅ | ✅ |
DuplicateTypeParameter |
✅ | ✅ |
MultipleCaseAssignment |
✅ | ✅ |
IrrefutableCasePattern |
✅ | ✅ |
SingleStarredAssignment |
✅ | ✅ |
WriteToDebug |
✅ | ✅ |
InvalidExpression |
✅ | ✅ |
DuplicateMatchKey |
✅ | ✅ |
DuplicateMatchClassAttribute |
✅ | ✅ |
LoadBeforeGlobalDeclaration |
✅ | ✅ |
InvalidStarExpression |
✅ | ✅ |
AsyncComprehensionInSyncComprehension |
✅ | ✅ |
YieldOutsideFunction |
✅ | ✅ |
ReturnOutsideFunction |
✅ | ✅ |
AwaitOutsideAsyncFunction |
✅ | ✅ |