Unify typing for `__path__`?
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 5.1k
- Forks
- 2.1k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 82
Descripción
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] |
https://github.com/python/typeshed/pull/6200 |
typeshed - pkgutil.extend_path |
list[str] |
https://github.com/python/typeshed/pull/5222 |
| mypy | list[str] |
https://github.com/python/mypy/pull/9454 |
| pyright | Iterable[str] |
https://github.com/microsoft/pylance-release/issues/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_pathcould 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__.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza comparando las anotaciones de typeshed ModuleType y pkgutil.extend_path con la documentación de Python sobre rutas de módulos y pkgutil, y después revisa las discusiones enlazadas de mypy y pyright. Determina un contrato de tipos coherente que refleje el comportamiento documentado y observado. Se considerará terminado cuando las anotaciones relevantes coincidan entre los stubs afectados y sigan siendo compatibles con extend_path.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- tooling
- Tipo de issue
- Refactorización
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Necesita aclaración
- Aptitud para principiantes
- 20/100