Skip to content
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

__path__ is inferred an Iterable[str] rather than list #10058

Open
aDotInTheVoid opened this issue Mar 11, 2025 · 1 comment
Open

__path__ is inferred an Iterable[str] rather than list #10058

aDotInTheVoid opened this issue Mar 11, 2025 · 1 comment
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working

Comments

@aDotInTheVoid
Copy link

Note: This is a regression of #1032. I've confirmed it appears in the latest released version.

Describe the bug

With the following code:

./mcve
└── __init__.py

mcve/__init__.py:

print(__path__[0])

(Code sample in pyright playground)

Pyright give errors:

% pyright ./mcve 
/Users/aloenr01/tmp/mcve/__init__.py
  /Users/aloenr01/tmp/mcve/__init__.py:1:7 - error: "__getitem__" method not defined on type "Iterable[str]" (reportIndexIssue)
1 error, 0 warnings, 0 informations 

But the code works fine:

% python3
Python 3.12.9 (main, Feb  4 2025, 14:38:38) [Clang 16.0.0 (clang-1600.0.26.6)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import mcve
/Users/aloenr01/tmp/mcve

VS Code extension or command-line

Command line: pyright 1.1.396

@aDotInTheVoid aDotInTheVoid added the bug Something isn't working label Mar 11, 2025
erictraut added a commit that referenced this issue Mar 11, 2025
…ce[str]`. Both are correct, but the latter is more precise. This addresses #10058.
@erictraut
Copy link
Collaborator

In response to bug #1032, I changed this from Iterable[str] to list[str] back in 2020. In early 2021, I reverted this change for reasons I don't recall. Unfortunately, I can't find the bug report or question that prompted the revert.

The type list[str] is narrower than what is required by the runtime, so changing the type of __path__ to list[str] would be incorrect. The type Iterable[str] is correct but probably wider than necessary. Based on the typeshed stubs, it appears that the correct type for this symbol is MutableSequence[str]. I'll change it to that.

erictraut added a commit that referenced this issue Mar 11, 2025
…ce[str]`. Both are correct, but the latter is more precise. This addresses #10058. (#10062)
@erictraut erictraut added the addressed in next version Issue is fixed and will appear in next published version label Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants