Replace `float` with `float | int`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.1k
- Forks
- 2.1k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the stdlib stubs and the _typeshed FloatInt and ComplexInt aliases, then inspect the flake8-pyi Y041 configuration. Search for float and complex annotations across the stdlib and review each candidate; completion means the planned stdlib-wide migration, while third-party stubs remain deferred until 2026-09-22.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100