Stub generation adds too many explicit re-exports
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 20.6k
- Forks
- 3.3k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
Bug Report
mypy stubgen re-exports more names than needed (despite --export-less). It seems that imports that are only used in function parameter type annotations (see FirstErrorType below) are always re-exported and imports from 'if TYPE_CHECKING' clauses (see SecondErrorType below) as well.
To Reproduce
# example.py
from typing import TYPE_CHECKING
from b import FirstErrorType, WorkingType
if TYPE_CHECKING:
from c import SecondErrorType
def foobar(one: FirstErrorType, two: "SecondErrorType") -> None:
pass
def spamandeggs() -> WorkingType:
return WorkingType()
Expected Behavior
Nether FirstErrorType nor SecondErrorType should be re-exported according to the documentation of the --export-less switch, which states
only export imported names that are not referenced in the module that contains the import.
Actual Behavior
the output of stubgen --export-less example.py
# example.pyi
from b import FirstErrorType as FirstErrorType, WorkingType
from c import SecondErrorType as SecondErrorType
def foobar(one: FirstErrorType, two: SecondErrorType) -> None: ...
def spamandeggs() -> WorkingType: ...
Your Environment
- Mypy version used: 1.13.0
- Mypy command-line flags: stubgen --export-less
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.10
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
Reproduce el problema con el example.py mostrado y ejecuta stubgen --export-less; después, inspecciona el example.pyi generado. Sigue el tratamiento que hace stubgen de las importaciones usadas únicamente para anotaciones y de las importaciones bajo TYPE_CHECKING; se considera terminado cuando FirstErrorType y SecondErrorType no son reexportaciones explícitas, mientras que WorkingType sigue exportándose.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- tooling
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100