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

Preserve block unreachablility when checking function definitions with constrained TypeVars #18217

Conversation

brianschubert
Copy link
Collaborator

Fixes #18210

When checking function definitions with constrained type variables (i.e. type variables with value restrictions), mypy expands the function definition for each possible type variable value. However, blocks in the expanded function definitions have their is_unreachable reset to False, which leads to spurious errors in blocks that were marked as unreachable during semantic analysis.

This PR preserves the value of is_unreachable on blocks in the expanded function definitions.

This comment has been minimized.

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Nice, thanks. Seems like it'd be reasonable to add a is_unreachable=False to Block.__init__

Copy link
Contributor

github-actions bot commented Dec 2, 2024

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

@hauntsaninja hauntsaninja merged commit e666217 into python:master Dec 2, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AnyStr parameter + sys.version_info check in function causes mypy to not realize True is bool
2 participants