Skip to content
Merged
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
5 changes: 3 additions & 2 deletions mypy/partially_defined.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from mypy.patterns import AsPattern, StarredPattern
from mypy.reachability import ALWAYS_TRUE, infer_pattern_value
from mypy.traverser import ExtendedTraverserVisitor
from mypy.types import Type, UninhabitedType
from mypy.types import Type, UninhabitedType, get_proper_type


class BranchState:
Expand Down Expand Up @@ -507,7 +507,8 @@ 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, type(None))):
typ = self.type_map.get(o.expr)
if typ is None or isinstance(get_proper_type(typ), UninhabitedType):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can this be tested?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I.e., can there be a test that would have failed without this change but now passes? It seems like that would have to require a non-"proper" type that resolves to UninhabitedType.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Can this be tested?

Probably not. The way I understand it, UninhabitedType is a synthetic type created by mypy itself to represent a true bottom type / never. Thus I guess it won't be part of a type alias.

The mypy plugin for get_proper_type doesn't seem to take that into account. Although I'm not sure it needs to. In these cases it's just a no-op. Easier to check it's always called on unexpanded types before isinstance checks.

self.tracker.skip_branch()
super().visit_expression_stmt(o)

Expand Down