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 dict.get issue for typeshed update #18806

Merged
merged 1 commit into from
Mar 16, 2025
Merged

Conversation

cdce8p
Copy link
Collaborator

@cdce8p cdce8p commented Mar 16, 2025

Fix for issue uncovered in #18803.

@cdce8p cdce8p mentioned this pull request Mar 16, 2025
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@@ -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
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
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
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.

@hauntsaninja hauntsaninja merged commit 5c87e97 into python:master Mar 16, 2025
18 checks passed
@cdce8p cdce8p deleted the fix-dict-get branch March 16, 2025 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants