Fix is_overlapping_types for generic callables#21208
Fix is_overlapping_types for generic callables#21208hauntsaninja wants to merge 2 commits intopython:masterfrom
Conversation
Fixes python#21182 This issue exposed this pre-existing deficiency in is_overlapping_types
for more information, see https://pre-commit.ci
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
ilevkivskyi
left a comment
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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.
Fixes #21182
This issue exposed this pre-existing deficiency in is_overlapping_types