Skip to content

Fix TypeIs narrowing to NewType - #22179

Open
nightcityblade wants to merge 1 commit into
python:masterfrom
nightcityblade:fix/issue-22175
Open

nightcityblade wants to merge 1 commit into
python:masterfrom
nightcityblade:fix/issue-22175

Conversation

@nightcityblade

Copy link
Copy Markdown

Fixes #22175

Preserve NewType targets when narrowing through TypeIs. Runtime isinstance checks still erase NewType to its base because they cannot distinguish the wrapper, while an explicit TypeIs predicate can now narrow to the declared NewType.

Adds regression coverage for both the positive and negative branches.

@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

scipy-stubs (https://github.com/scipy/scipy-stubs)
- tests/misc/test_submodules_empty.pyi:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

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.

TypeIs doesn't narrow a NewType

1 participant