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 TypeIs negative narrowing of union of generics #18193

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

brianschubert
Copy link
Collaborator

Fixes #18009

Modelling the runtime behavior of isinstance (which erases generic type arguments) isn't applicable to TypeIs. This PR adds a flag so that we can skip that logic deep inside conditional_types_with_intersection.

It's a little awkward having to pass a flag down through so many call levels, but I can't think of a better way.

This comment has been minimized.

@brianschubert brianschubert marked this pull request as draft November 26, 2024 21:20
Copy link
Contributor

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

pydantic (https://github.com/pydantic/pydantic)
+ pydantic/fields.py:606: error: Redundant cast to "Callable[[], Any]"  [redundant-cast]

pytest (https://github.com/pytest-dev/pytest)
+ testing/test_monkeypatch.py:418: error: Unused "type: ignore" comment  [unused-ignore]

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.

Type narrowed to Never when using TypeIs with union of callables
1 participant