-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[red-knot] Track reachability of scopes #17332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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-reference
diagnostics (and in the future,unresolved-attribute
andunresolved-import
). This means that we only emitunresolved-reference
for 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 ofx
here: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.