Calling `type[T]` returns the parent of `T` on Python 3.12+
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 20.6k
- Forks
- 3.3k
- Merge medio
- 1 d 18 h
- PR fusionados (30 d)
- 54
Descripción
Bug Report / To Reproduce
Ok so this is a weird one, and I've been completely unable to replicate it in an MRE. So here's the PR where this happened to us: https://github.com/pypa/setuptools/pull/4726
To replicate, clone the setuptools repo, install the [core,type] extras, then change the start of setuptools/command/install.py's install.do_egg_install to:
def do_egg_install(self) -> None:
easy_install = cast(
type[easy_install_cls], self.distribution.get_command_class('easy_install')
)
cmd = easy_install(
self.distribution,
args="x",
root=self.root,
record=self.record,
)
reveal_type(cmd)
On Python 3.11
setuptools\command\install.py:150: note: Revealed type is "setuptools.command.easy_install.easy_install"
Success: no issues found in 143 source files
On Python 3.12 & 3.13
setuptools\command\install.py:150: note: Revealed type is "setuptools.Command"
setuptools\command\install.py:166: error: Unexpected keyword argument "show_deprecation" for "run" of "Command" [call-arg]
Found 1 error in 1 file (checked 143 source files)
My first guess is this has something to do with distutils removal in 3.12, but the results I'm getting are still nonsensical and probably reveal a hidden bug in mypy.
Expected Behavior
cmd should be of type setuptools.command.easy_install or alias easy_install_cls
Actual Behavior
cmd is of type setuptools.Command (superclass of setuptools.command.easy_install)
Your Environment
- Mypy version used: 1.12.1 and 1.13
- Mypy command-line flags:
python3.1X -m mypy . - Mypy configuration options from
mypy.ini(and other config files): https://github.com/pypa/setuptools/blob/39179c1fcbd3509adebb4b379dd790f735c1ee69/mypy.ini - Python version used: 3.9 - 3.13
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
Empieza reproduciendo el informe en setuptools/command/install.py usando mypy con Python 3.11, 3.12 y 3.13, y compara el tipo mostrado para cmd. Revisa el pull request de setuptools enlazado y la configuración de mypy.ini; estará terminado cuando el cast a type[easy_install_cls] muestre el tipo easy_install esperado sin el error espurio de Command.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- compilers, devtools
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100