python / python/typeshed

Replace `float` with `float | int`

Abierto
#16,059 5 comentarios 5 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

project: policy
Lenguaje dominante
Python
Estrellas
5.1k
Forks
2.1k
Merge medio
1 d 19 h
PR fusionados (30 d)
82

Descripción

As discussed in python/typing#1748: I propose to (slowly) replace float with float | int and complex with complex | float | int, where applicable.

  • It's more correct, even if float is current implicitly equivalent to int | float.
  • We are already prepared should the implicit promotion ever be removed.
  • We give type checkers the ability to optionally disable the promotion so that type checker authors and users can experiment with it.
  • Typeshed would always need to be the first step for this, so let's remove this blocker.

This issue proposes an ugly and slow, but correct and safe procedure:

  1. Disable flake8-pyi code Y041.
    #16096
  2. Introduce two type aliases FloatInt = float | int and ComplexInt = complex | float | int to _typeshed.
    #16068
  3. Globally replace all instances of float with FloatInt and of complex with ComplexInt in the stdlib.
  4. After 2026-09-22 we do the same for third-party stubs.
  5. Review FloatInt and ComplexInt instances are replace them with the proper types. (This will take a while.)
  6. Remove the type aliases once they are not needed anymore (in 10 years or so ...)

Using FloatInt and ComplexInt would be disallowed for new code and the type aliases should explicitly be marked as not to be used by non-typeshed code.

We should also probably add flake8-pyi checks that checks that argument types use float | int and complex | float | int. Cases where only float/complex is allowed are probably rare.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con los stubs de la stdlib y los alias FloatInt y ComplexInt de _typeshed; después, inspecciona la configuración Y041 de flake8-pyi. Busca anotaciones float y complex en toda la stdlib y revisa cada candidato; la finalización implica la migración planificada de toda la stdlib, mientras que los stubs de terceros quedan aplazados hasta el 2026-09-22.

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
Tranquilo
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.