ruff/crates/red_knot_python_semantic/resources/mdtest/import
Brent Westbrook e7f38fe74b
[red-knot] Detect semantic syntax errors (#17463)
Summary
--

This PR extends semantic syntax error detection to red-knot. The main
changes here are:

1. Adding `SemanticSyntaxChecker` and `Vec<SemanticSyntaxError>` fields
to the `SemanticIndexBuilder`
2. Calling `SemanticSyntaxChecker::visit_stmt` and `visit_expr` in the
`SemanticIndexBuilder`'s `visit_stmt` and `visit_expr` methods
3. Implementing `SemanticSyntaxContext` for `SemanticIndexBuilder`
4. Adding new mdtests to test the context implementation and show
diagnostics

(3) is definitely the trickiest and required (I think) a minor addition
to the `SemanticIndexBuilder`. I tried to look around for existing code
performing the necessary checks, but I definitely could have missed
something or misused the existing code even when I found it.

There's still one TODO around `global` statement handling. I don't think
there's an existing way to look this up, but I'm happy to work on that
here or in a separate PR. This currently only affects detection of one
error (`LoadBeforeGlobalDeclaration` or
[PLE0118](https://docs.astral.sh/ruff/rules/load-before-global-declaration/)
in ruff), so it's not too big of a problem even if we leave the TODO.

Test Plan
--

New mdtests, as well as new errors for existing mdtests

---------

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2025-04-23 09:52:58 -04:00
..
basic.md [red-knot] Case sensitive module resolver (#16521) 2025-03-14 19:16:44 +00:00
builtins.md [red-knot] improve function/bound method type display (#17294) 2025-04-14 15:56:18 -07:00
case_sensitive.md [red-knot] Case sensitive module resolver (#16521) 2025-03-14 19:16:44 +00:00
conditional.md [red-knot] improve function/bound method type display (#17294) 2025-04-14 15:56:18 -07:00
conflicts.md [red-knot] Enforce specifying paths for mdtest code blocks in a separate preceding line (#15890) 2025-02-04 08:27:17 +01:00
conventions.md Use python.typing.org for typing documentation links (#17323) 2025-04-09 20:38:20 +02:00
errors.md [red-knot] Enforce specifying paths for mdtest code blocks in a separate preceding line (#15890) 2025-02-04 08:27:17 +01:00
invalid_syntax.md [red-knot] Enforce specifying paths for mdtest code blocks in a separate preceding line (#15890) 2025-02-04 08:27:17 +01:00
relative.md [red-knot] Fix python setting in mdtests, and rewrite a site-packages test as an mdtest (#17222) 2025-04-06 18:24:32 +01:00
star.md [red-knot] Detect semantic syntax errors (#17463) 2025-04-23 09:52:58 -04:00
stub_packages.md [red-knot] Support stub packages (#17204) 2025-04-07 14:40:50 +02:00
stubs.md [red-knot] Enforce specifying paths for mdtest code blocks in a separate preceding line (#15890) 2025-02-04 08:27:17 +01:00
tracking.md [red-knot] Enforce specifying paths for mdtest code blocks in a separate preceding line (#15890) 2025-02-04 08:27:17 +01:00