-
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
"Type of ... is partially unknown" with reflexive types #721
Comments
@erictraut could you please take a look? |
This will work if you make the following change: ContentsDictType = Dict[str, "ContentsEntryType"] Some additional background on why this change is required... The challenge here is with recursive type definitions that include types with invariant type parameters (such as Dict, MutableMapping, or List). If we strictly adhere to the definition of an "invariant TypeVar" as explained in PEP 483 and 484, recursive type definitions that involve invariant type parameters cannot be supported because there's no way for a recursive type to be invariant with itself. When I introduced support for recursive type alias definitions in Pyright/Pylance, I needed bend the rules a little bit to accommodate this problem. This comes with the limitation that we don't support hierarchies of types that support invariant TypeVars. You must use the exact type in the type alias. In your case, you used |
Thank you! So if I understood correctly, the Python's type system specification seems to have a bug, as other programming languages are able to resolve such situations. I encountered another problem: from typing import (Dict, Union)
ContentsDictType = Dict[str, "ContentsEntryType"]
ContentsEntryType = Union["ContentsDictType", bool]
entry: ContentsEntryType = dict() Message:
|
@erictraut Seems like we missed this one; I can reproduce the above in the latest release where entry is partially unknown. |
Yeah, there are limitations involved with using recursive type definitions. Supporting these even in limited cases is very difficult in Python. No other type checkers have any support for them currently. I'll take a look at this particular case to see if it's feasible to address. In the meantime, there's a simple workaround. Just combine the two definitions into a single entry: ContentsEntryType = Union[Dict[str, "ContentsEntryType"], bool] |
Yes, this is easy to fix. It will be addressed in the next release. |
This issue has been fixed in version 2021.1.3, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202113-27-january-2021 |
Environment data
Expected behaviour
no error
Actual behaviour
output in problem panel:
Logs
Code Snippet / Additional information
Uncommenting the first line makes no difference.
The text was updated successfully, but these errors were encountered: