Replace `float` with `float | int`
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 5.1k
- Forks
- 2.1k
- Merge moyen
- 1 j 19 h
- PR mergées (30 j)
- 82
Description
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
floatis current implicitly equivalent toint | 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:
- Disable flake8-pyi code Y041.
#16096 - Introduce two type aliases
FloatInt = float | intandComplexInt = complex | float | intto_typeshed.
#16068 - Globally replace all instances of
floatwithFloatIntand ofcomplexwithComplexIntin the stdlib. - After 2026-09-22 we do the same for third-party stubs.
- Review
FloatIntandComplexIntinstances are replace them with the proper types. (This will take a while.) - 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.
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par les stubs de la stdlib et les alias FloatInt et ComplexInt de _typeshed, puis examinez la configuration Y041 de flake8-pyi. Recherchez les annotations float et complex dans toute la stdlib et examinez chaque candidat ; l’achèvement correspond à la migration prévue de toute la stdlib, tandis que les stubs tiers restent reportés jusqu’au 2026-09-22.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- tooling
- Type d'issue
- Refactorisation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- Calme
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100