fix: TypeGuard becomes bool instead of Any when passed as TypeVar (fixes #17117)#17145
fix: TypeGuard becomes bool instead of Any when passed as TypeVar (fixes #17117)#17145hauntsaninja merged 5 commits intopython:masterfrom
Conversation
mypy/constraints.py
Outdated
| elif template.type_guard is not None: | ||
| template_ret_type = AnyType(TypeOfAny.special_form) |
There was a problem hiding this comment.
Does this branch make sense?
When we use TypeGuard or TypeIs in template it seems that we should use TypeGuard/TypeIs in actual too. Otherwise, we get Never type in the previous steps. Is it true? I'm a little confused here...
There was a problem hiding this comment.
I think we can get rid of this branch as well. And yeah, all tests pass if I do.
(There's might also be some latent bug with TypeGuard and TypeIs mixing)
There was a problem hiding this comment.
Yes, it's probably better to remove this branch too. I think when I implemented TypeIs I assumed we needed this to make bool and TypeGuard/TypeIs unify, but that doesn't seem to be the case.
There was a problem hiding this comment.
Got it, thanks for your comments! Removed that elif-s for TypeGuard/TypeIs.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
60ded21 to
b167022
Compare
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
|
Thank you! |
Fixes #17117.