-
Notifications
You must be signed in to change notification settings - Fork 767
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
Inference for empty in-place container types #1736
Comments
Here's what's going on. The type of the subexpression The reason this works with a combination of lists is due to special-case handling in the type inference code for There is one case above that could be made to work with some straightforward special-casing logic: the The other cases above would require much hackier special casing, embedding deep semantic knowledge of these types in the type checker. We generally don't do this unless it's a really common use case because these special cases make the code less maintainable and slower — and often break other edge cases within the type analysis. We can see if we get signal from other users that this is justified here, but for now I'm going to leave the behavior as is for the non-tuple case. This gives you a couple of viable workarounds to handle your use case. |
Thanks for looking into it! Usually, I only come across I found the other cases while investigating under which circumstances this happens. Thought I mention them as well, since I already found them. |
@erictraut Was this fixed in microsoft/pyright@49d9c7c? |
Ah, I see, you said it was special cased just for that one case. |
With the commit, I would consider it fixed. As mentioned before, the other cases have only really been for debugging purposes. |
This issue has been fixed in version 2021.7.0, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202190-1-september-2021 |
Environment data
Expected behaviour
Revealed type should be
item: str
Actual behaviour
item: str | Any
Logs
--Code Snippet / Additional information
Mypy will infer
builtins.str*
in all cases.--
Note: It does work correctly if an empty list is used.
The text was updated successfully, but these errors were encountered: