Skip to content

Fix is_overlapping_types for generic callables#21208

Open
hauntsaninja wants to merge 2 commits intopython:masterfrom
hauntsaninja:genericoverlap
Open

Fix is_overlapping_types for generic callables#21208
hauntsaninja wants to merge 2 commits intopython:masterfrom
hauntsaninja:genericoverlap

Conversation

@hauntsaninja
Copy link
Copy Markdown
Collaborator

Fixes #21182

This issue exposed this pre-existing deficiency in is_overlapping_types

Fixes python#21182

This issue exposed this pre-existing deficiency in is_overlapping_types
@github-actions
Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

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

This is good as a hot-fix, but TBH I am not 100% happy with the behavior in this case. So maybe add a TODO or a follow-up issue?

def msg(cmp_property: Callable[[T], S]) -> None:
if cmp_property == identity:
reveal_type(cmp_property) # N: Revealed type is "def [T] (x: T`-1) -> T`-1"
reveal_type(identity) # N: Revealed type is "def (T`-1) -> S`-2"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Although we fix the unreachable error, this "flipping" behavior in IMO surprising. Would it make sense for each expression to keep its own type if the intersection is not expressible?

Btw, in this case the intersection is expressible, it is Overloaded(def (T) -> S, def [U](x: U) -> U), but if we are going to do this we will need to do some (expensive) validation, plus freshening to avoid accidental TypeVar id clashes, and this would be way too big change for a point release.

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.

[1.20 regression] unreachable regression with generic Callable

2 participants