-
Notifications
You must be signed in to change notification settings - Fork 771
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
Wrong type of module.__path__? #1098
Comments
Thanks for the bug report. You're correct, the type of |
This issue has been fixed in version 2021.3.4, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202134-31-march-2021 |
Sorry for reopening it, but I came across this issue while updating mypy to 0.920. Technically The stubs from With mypy 0.920, The original mypy issue: python/mypy#1422 -- # file: some_module/__init__.py
print(__path__[0]) |
Based on the Python docs, it would be legitimate to assign an immutable iterable type to |
Probably? I don't know enough about it to be sure. If the input path is not a list (as is the case for frozen
packages) it is returned unchanged. The input path is not
modified; an extended copy is returned. Items are only appended
to the copy at the end. That would indeed suggest that if not isinstance(path, list):
# This could happen e.g. when this is called from inside a
# frozen package. Return the path unchanged in that case.
return path -- Another aspect to consider, how common is it for users to try to modify |
I don't have a strong opinion about this, but I don't want to keep changing it. I've already changed this once, and the current code appears to match the Python documentation. Before changing it again, I'd like to get a definitive answer — or at least an indication that there's consensus within the typing and typeshed communities on the right answer. If you are so motivated, please drive that process and once there's consensus, file a new pyright feature request for the change. Thanks! |
Environment data
Expected behaviour
Pylance treats
__path__
as anIterable[str]
(it should be treated as such according to the Python docs) and doesn't show an error when trying to assign the result ofpkgutil.extend_path
to it.Actual behaviour
Pylance says the type of
__path__
islist[str]
and shows an error sayingLogs
Python Language Server Log
Code Snippet / Additional information
The text was updated successfully, but these errors were encountered: