-
-
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
False positive [unreachable] with TypeIs
#17181
Comments
I think the issue is probably a general type narrowing problem of the AnalysisI had a quick look into the implementation and it seems that the code of the
Problem
Erasing the type argument is fine for
|
Thanks for the analysis! I'd be happy to review a PR addressing this. |
I was already thinking about submitting one, but I thought it is best to wait until it is confirmed (which you did just now ;) ) I will have a look 👍 |
This isn't a problem in basedmypy: playground I think it involved updating I think the problem arises in # Since runtime type checks will ignore type arguments, erase the types. |
I checked the code in basedmypy and it seems that
(This PR should handle these cases.) |
Bug Report
Applying
TypeIs
to narrow type of an iterable results in too optimistic reachability analysis.To Reproduce
playground has more code, including
TypeGuard
comparison and non-iterable case that works correctly.Expected Behavior
I'd expected both branches to be reachable and to narrow type according to the spec:
list[int]
inif
andlist[str]
inelse
, ideally.Actual Behavior
Your Environment
--warn-unreachable
mypy.ini
(and other config files): N/AThe text was updated successfully, but these errors were encountered: