Repository navigation
Conversation
Summary: Stack context: pyrefly does not report a suite as unreachable when its `if` test is a walrus (`x := value`) whose value is always false or always true. - What: add a passing test, marked `bug`, that shows the missing "This code is unreachable" errors for walrus tests. - Why: the next diff fixes this and updates the expectations. Differential Revision: D129211785
Summary: Stack context: pyrefly does not report a suite as unreachable when its `if` test is a walrus (`x := value`) whose value is always false or always true. - Problem: `if x := value:` with `value: Literal[False]` does not report its body as unreachable, but `if value:` does. The same happens with a class whose `__bool__` returns `Literal[False]`, for example `if genre := (author and author.genre):`. `declared_bool_value` has no case for `Expr::Named`, so a walrus test never gets a fixed value. - Fix: a walrus test takes the declared value of the expression it assigns. Differential Revision: D129211786
Contributor
|
@kinto0 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D129211786. |
|
Diff from mypy_primer, showing the effect of this PR on open source code: ============================================================
SUMMARY
============================================================
Total: +3 new errors, -0 fixed errors
By preset: +3/-0 (default), +3/-0 (strict)
Projects with changes (2):
pytest-autoprofile: +2 -0
core: +1 -0
============================================================
FULL DIFF DETAILS
------------------------------------------------------------
pytest-autoprofile (https://gitlab.com/TTsangSC/pytest-autoprofile)
+ ERROR tests/test-modules-and-tests/test_subprocess/tests/test_func.py:29:5-21: This code is unreachable [unreachable]
+ ERROR tests/test_subprocess.py:40:5-41:21: This code is unreachable [unreachable]
core (https://github.com/home-assistant/core)
+ ERROR homeassistant/components/tuya/climate.py:367:13-64: This code is unreachable [unreachable] |
Contributor
|
This pull request has been merged in b44689a. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Stack context: pyrefly does not report a suite as unreachable when its
iftest is a walrus (x := value) whose value is always false or always true.if x := value:withvalue: Literal[False]does not report its body as unreachable, butif value:does. The same happens with a class whose__bool__returnsLiteral[False], for exampleif genre := (author and author.genre):.declared_bool_valuehas no case forExpr::Named, so a walrus test never gets a fixed value.Differential Revision: D129211786
fixes #5499