-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Checks module bodies to be reachable #11361
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
Changes from all commits
8f8e9b6
582e6f9
c165a58
8333ae6
ba9c53a
2d51fb8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -754,35 +754,46 @@ if sys.version_info[0] >= 2: | |
reveal_type('') # N: Revealed type is "Literal['']?" | ||
[builtins fixtures/ops.pyi] | ||
|
||
[case testUnreachableFlagWithBadControlFlow] | ||
[case testUnreachableFlagWithBadControlFlow1] | ||
# flags: --warn-unreachable | ||
a: int | ||
if isinstance(a, int): | ||
reveal_type(a) # N: Revealed type is "builtins.int" | ||
else: | ||
reveal_type(a) # E: Statement is unreachable | ||
[builtins fixtures/isinstancelist.pyi] | ||
|
||
[case testUnreachableFlagWithBadControlFlow2] | ||
# flags: --warn-unreachable | ||
b: int | ||
while isinstance(b, int): | ||
reveal_type(b) # N: Revealed type is "builtins.int" | ||
else: | ||
reveal_type(b) # E: Statement is unreachable | ||
[builtins fixtures/isinstancelist.pyi] | ||
|
||
[case testUnreachableFlagWithBadControlFlow3] | ||
# flags: --warn-unreachable | ||
def foo(c: int) -> None: | ||
reveal_type(c) # N: Revealed type is "builtins.int" | ||
assert not isinstance(c, int) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could be a clearer statement of intent to explicitly raise an exception here. This will not make the code below unreachable if run with assertions disabled, which you can do in Python. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, because we already have tests for explicit There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see. I guess my point is that |
||
reveal_type(c) # E: Statement is unreachable | ||
[builtins fixtures/isinstancelist.pyi] | ||
|
||
[case testUnreachableFlagWithBadControlFlow4] | ||
# flags: --warn-unreachable | ||
d: int | ||
if False: | ||
reveal_type(d) # E: Statement is unreachable | ||
[builtins fixtures/isinstancelist.pyi] | ||
|
||
[case testUnreachableFlagWithBadControlFlow5] | ||
# flags: --warn-unreachable | ||
e: int | ||
if True: | ||
reveal_type(e) # N: Revealed type is "builtins.int" | ||
else: | ||
reveal_type(e) # E: Statement is unreachable | ||
|
||
[builtins fixtures/isinstancelist.pyi] | ||
|
||
[case testUnreachableFlagStatementAfterReturn] | ||
|
@@ -1390,3 +1401,18 @@ def f() -> None: | |
if nope(): | ||
x = 1 # E: Statement is unreachable | ||
[builtins fixtures/dict.pyi] | ||
|
||
[case testUnreachableModuleBody1] | ||
# flags: --warn-unreachable | ||
from typing import NoReturn | ||
def foo() -> NoReturn: | ||
raise Exception("foo") | ||
foo() | ||
x = 1 # E: Statement is unreachable | ||
[builtins fixtures/exception.pyi] | ||
|
||
[case testUnreachableModuleBody2] | ||
# flags: --warn-unreachable | ||
raise Exception | ||
x = 1 # E: Statement is unreachable | ||
[builtins fixtures/exception.pyi] |
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.
self.accept(Block(self.tree.defs))
didn't work. Let's try explicit condition.