Skip to content
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

Fix partially defined in the case of missing type maps #15995

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/partially_defined.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ def visit_break_stmt(self, o: BreakStmt) -> None:
self.tracker.skip_branch()

def visit_expression_stmt(self, o: ExpressionStmt) -> None:
if isinstance(self.type_map.get(o.expr, None), UninhabitedType):
if isinstance(self.type_map.get(o.expr, None), (UninhabitedType, type(None))):
self.tracker.skip_branch()
super().visit_expression_stmt(o)

Expand Down
17 changes: 17 additions & 0 deletions test-data/unit/check-possibly-undefined.test
Original file line number Diff line number Diff line change
Expand Up @@ -1026,3 +1026,20 @@ class B:
else:
# Same as above but in a loop.
b = a # E: Name "a" may be undefined

[case testUnreachableCausingMissingTypeMap]
# flags: --enable-error-code possibly-undefined --enable-error-code used-before-def --no-warn-unreachable
# Regression test for https://github.com/python/mypy/issues/15958
from typing import Union, NoReturn

def assert_never(__x: NoReturn) -> NoReturn: ...

def foo(x: Union[int, str]) -> None:
if isinstance(x, str):
f = "foo"
elif isinstance(x, int):
f = "bar"
else:
assert_never(x)
f # OK
[builtins fixtures/tuple.pyi]
Comment on lines +1030 to +1045
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be worth adding a match/case test as well, or would that just be unnecessarily duplicative?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good q, I think just duplicative. (fwiw I'd changed to if since that runs on all Python versions)