Replace `float` with `float | int`
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 5.1k
- Fork
- 2.1k
- Merge medio
- 1g 19h
- PR unite (30g)
- 82
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia dagli stub della stdlib e dagli alias FloatInt e ComplexInt di _typeshed, quindi esamina la configurazione Y041 di flake8-pyi. Cerca annotazioni float e complex in tutta la stdlib e verifica ogni candidato; il completamento consiste nella migrazione pianificata dell’intera stdlib, mentre gli stub di terze parti restano rimandati fino al 2026-09-22.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- tooling
- Tipo di issue
- Refactoring
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100