-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Description
After the last mypy update v0.920, I started to notice an inconsistency with how the module variable __path__
is typed mainly across typeshed, mypy, and pyright.
Type | Link | |
---|---|---|
typeshed - ModuleType |
MutableSequence[str] |
#6200 |
typeshed - pkgutil.extend_path |
list[str] |
#5222 |
mypy | list[str] |
python/mypy#9454 |
pyright | Iterable[str] |
microsoft/pylance-release#1098 |
In the Python docs it's mentioned as:
`__path__` must be an iterable of strings, but it may be empty.
However the docs for pkgutil.extend_path
go on say it's mostly a list (?) cpython/pkgutil.py
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.
From my point of view, it isn't entirely clear what the "correct" type should be. Some points to consider though:
- In most cases it seems to be a
list[str]
. - It was mentioned here however that it can sometimes also be a
MutableSequence[str]
- The
__path__
type should be valid as first argument topkgutil.extend_path
. At the moment that only applies tolist[str]
but obviously the argument type forextend_path
could be changed to, for example, accept a TypeVar bound toIterable[str]
instead. - It seems to be fairly common (and safe ?) to access the at least the first item of
__path__
via__getitem__
.
Metadata
Metadata
Assignees
Labels
No labels