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
base: master
Are you sure you want to change the base?
Conversation
mypy/constraints.py
Outdated
bool_type = UnionType( | ||
[LiteralType(True, cactual_ret_type), LiteralType(False, cactual_ret_type)] # type: ignore[arg-type] | ||
) |
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.
It seems ugly, but I can't find another way to create Instance
of builtins.bool
. It also leads to the CI failure :(
Oh, I got that we can use just cactual_ret_type without rewriting it...
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...
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Fixes #17117.