python / python/typeshed

Replace `float` with `float | int`

Aperta
#16,059 5 commenti 5 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

project: policy
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 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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. 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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.