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

Merged
merged 5 commits into from
Oct 18, 2024

Conversation

sloboegen
Copy link
Contributor

Fixes #17117.

mypy/constraints.py Outdated Show resolved Hide resolved
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...

Copy link
Collaborator

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)

Copy link
Member

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.

Copy link
Contributor Author

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.

1 similar comment

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

@hauntsaninja hauntsaninja merged commit 5d9b1f9 into python:master Oct 18, 2024
17 checks passed
@hauntsaninja
Copy link
Collaborator

Thank you!

@sloboegen sloboegen deleted the issue-17117 branch October 18, 2024 05:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(🐞) TypeGuard passed to a TypeVar becomes Any, not bool
3 participants