-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
cannot narrow some-type|Any to some-type by isinstance #4508
Comments
I agree this is inconsistent. I've updated the |
…g the narrowing of a type that contains a union with `Any` or `Unknown`. This addresses #4508.
I needed to back out this change for now because it introduced a regression in some other |
…g the narrowing of a type that contains a union with `Any` or `Unknown`. This addresses #4508.
I found a way to make both cases work. This will be included in the next release. |
This is included in pyright 1.1.291, which I just published. It will also be included in a future release of pylance. |
Describe the bug
Union
s can be narrowed to it's element type byisinstance
as described in https://github.com/microsoft/pyright/blob/main/docs/type-concepts.md#type-narrowing .but, for example
Union[str,Any]
cannot be narrowed tostr
byisinstance(..., str)
.To Reproduce
Expected behavior
in above example, all
reveal_type
inif isinstance(..., str):
should outputstr
.VS Code extension or command-line
command-line tool, 1.1.290
The text was updated successfully, but these errors were encountered: