-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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: TypeGuard becomes bool instead of Any when passed as TypeVar (fixes #17117) #17145
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.