KEMBAR78
Preserve block unreachablility when checking function definitions with constrained TypeVars by brianschubert · Pull Request #18217 · python/mypy · GitHub
Skip to content

Conversation

brianschubert
Copy link
Member

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.

@github-actions

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__

@github-actions
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