[red-knot] Track reachability of scopes#17332
Conversation
|
This one is interesting -- looks like a buggy type annotation in |
Came to the exact same conclusion. I was also confused at first. Edit: this might explain it. Maybe |
AlexWaygood
left a comment
There was a problem hiding this comment.
Nice, this looks excellent
|
Love this! |
* main: (30 commits) [red-knot] Silence `unresolved-import` in unreachable code (#17336) red_knot_python_semantic: move TODO comment red_knot_python_semantic: rename `lint()` and `report()` ruff_db: use `Annotation::get_message` in more places red_knot_python_semantic: tweak docs on building reporter builders red_knot_python_semantic: remove the "old" secondary message type red_knot_python_semantic: replace one use of "old" secondary diagnostic messages red_knot_python_semantic: update revealed type snapshots ruff_db: tweak how the revealed type diagnostic is rendered red_knot: add explicit test for concise `reveal_type` diagnostic red_knot_python_semantic: remove `InferContext::report_diagnostic` red_knot_python_semantic: add "reporter" API Bump 0.11.5 (#17337) [red-knot] Silence `unresolved-attribute` in unreachable code (#17305) Revert "[red-knot] Type narrowing for assertions (#17149)" (#17335) [red-knot] Type narrowing for assertions (#17149) [red-knot] avoid unnecessary evaluation of visibility constraint on definitely-unbound symbol (#17326) update cargo-dist (#17325) [red-knot] Fix double hovers/inlays in playground (#17334) [red-knot] Track reachability of scopes (#17332) ...

Summary
Track the reachability of nested scopes within their parent scopes. We use this as an additional requirement for emitting
unresolved-referencediagnostics (and in the future,unresolved-attributeandunresolved-import). This means that we only emitunresolved-referencefor a given use of a symbol if the use itself is reachable (within its own scope), and if the scope itself is reachable. For example, no diagnostic should be emitted for the use ofxhere:There are probably more fine-grained ways of solving this problem, but they require a more sophisticated understanding of nested scopes (see astral-sh/ty#210, in particular astral-sh/ty#210). But it doesn't seem completely unreasonable to silence this specific kind of error in unreachable scopes.
Test Plan
Observed changes in reachability tests and ecosystem.