-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[red-knot] Consider all definitions after terminal statements unreachable #15676
base: main
Are you sure you want to change the base?
Conversation
|
There are a couple of new diagnostics in the benchmark that don't look correct to me. I need to see if I can minimize that into an mdtest to diagnose. |
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.
Fantastic!! Love to see a feature that is easier than anticipated :)
crates/red_knot_python_semantic/resources/mdtest/terminal_statements.md
Outdated
Show resolved
Hide resolved
crates/red_knot_python_semantic/resources/mdtest/terminal_statements.md
Outdated
Show resolved
Hide resolved
crates/red_knot_python_semantic/resources/mdtest/terminal_statements.md
Outdated
Show resolved
Hide resolved
crates/red_knot_python_semantic/resources/mdtest/terminal_statements.md
Outdated
Show resolved
Hide resolved
* main: [red-knot] MDTests: Do not depend on precise public-symbol type inference (#15691) [red-knot] Make `infer.rs` unit tests independent of public symbol inference (#15690) Tidy knot CLI tests (#15685) [red-knot] Port comprehension tests to Markdown (#15688) Create Unknown rule diagnostics with a source range (#15648) [red-knot] Port 'deferred annotations' unit tests to Markdown (#15686) [red-knot] Support custom typeshed Markdown tests (#15683) Don't run the linter ecosystem check on PRs that only touch red-knot crates (#15687) Add `rules` table to configuration (#15645) [red-knot] Make `Diagnostic::file` optional (#15640) [red-knot] Add test for nested attribute access (#15684) [red-knot] Anchor relative paths in configurations (#15634) [`pyupgrade`] Handle multiple base classes for PEP 695 generics (`UP046`) (#15659) [`pyflakes`] Treat arguments passed to the `default=` parameter of `TypeVar` as type expressions (`F821`) (#15679) Upgrade zizmor to the latest version in CI (#15649) [`pyupgrade`] Add rules to use PEP 695 generics in classes and functions (`UP046`, `UP047`) (#15565) [red-knot] Ensure a gradual type can always be assigned to itself (#15675)
I don't think you need to change anything for this PR, but just so it's on your radar: def f():
x = 1
while True:
try:
break
finally:
x = 2
reveal_type(x) # revealed: Literal[2] (it gives a revealed type of |
Yeah, we can handle |
Co-authored-by: Carl Meyer <[email protected]>
* main: Add `check` command (#15692) [red-knot] Use itertools to clean up `SymbolState::merge` (#15702) [red-knot] Add `--ignore`, `--warn`, and `--error` CLI arguments (#15689) Use `uv init --lib` in tutorial (#15718) [red-knot] Use `Unknown | T_inferred` for undeclared public symbols (#15674) [`ruff`] Parenthesize fix when argument spans multiple lines for `unnecessary-round` (`RUF057`) (#15703) [red-knot] Rename `TestDbBuilder::typeshed` to `.custom_typeshed` (#15712) Honor banned top level imports by TID253 in PLC0415. (#15628) Apply `AIR302`-context check only in `@task` function (#15711) [`airflow`] Update `AIR302` to check for deprecated context keys (#15144) Remove test rules from JSON schema (#15627) Add two missing commits to changelog (#15701) Fix grep for version number in docker build (#15699) Bump version to 0.9.3 (#15698) Preserve raw string prefix and escapes (#15694) [`flake8-pytest-style`] Rewrite references to `.exception` (`PT027`) (#15680)
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.
For example, the following test fails on this branch:
Thanks @dylwil3! I added that as a failing test case. I'm going to poke at it briefly to see if it's easy to add for this PR
crates/red_knot_python_semantic/resources/mdtest/terminal_statements.md
Outdated
Show resolved
Hide resolved
crates/red_knot_python_semantic/resources/mdtest/terminal_statements.md
Outdated
Show resolved
Hide resolved
reveal_type(x) # revealed: Literal["continue"] | ||
continue | ||
reveal_type(x) # revealed: Literal["loop"] | ||
reveal_type(x) # revealed: Literal["before", "loop"] |
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.
Ooh, this is now incorrect. It should be Literal["before", "loop", "continue"]
:
If i <= 0
, the loop body won't execute, and x == "before"
.
If i > 0 and cond
, the loop body will execute i
times, each time assigning "loop"
.
If i > 0 and not cond
, the loop body will execute i
times, each time assigning "continue"
.
The continue
statement should mark its flow as unreachable for when we join the if
branches. But it should not be considered unreachable when we join with the for
loop's continuation and exit paths.
We can use the new statically known branches feature to address #14014, by adding an "always false" visibility constraint immediately after each terminal statement.
Test Plan
The new mdtests failed (with incorrect
reveal_type
results, and spuriouspossibly-unresolved-reference
errors) before adding the new visibility constraints.