Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

sloboegen
Copy link
Contributor

Fixes #17117.

Comment on lines 1021 to 1023
bool_type = UnionType(
[LiteralType(True, cactual_ret_type), LiteralType(False, cactual_ret_type)] # type: ignore[arg-type]
)
Copy link
Contributor Author

@sloboegen sloboegen Apr 20, 2024

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...

Comment on lines 1028 to 1029
elif template.type_guard is not None:
template_ret_type = AnyType(TypeOfAny.special_form)
Copy link
Contributor Author

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.

Copy link
Contributor

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

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.

(🐞) TypeGuard passed to a TypeVar becomes Any, not bool
1 participant