Skip to content

[stdlib] Replace float with FloatInt - #16788

Open
srittau wants to merge 3 commits into
python:mainfrom
srittau:float-int-stdlib
Open

srittau wants to merge 3 commits into
python:mainfrom
srittau:float-int-stdlib

Conversation

@srittau

@srittau srittau commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Keep float in the following cases:

  • If it's already in an union with int.
  • Return types (also in compound return types).
  • Return types of Callable types.
  • Type arguments of base classes.
  • Type var constraints.

This was mainly generated using a codemod, and manually verified. Manual changes:

  • Reordered float/int unions to a consistent order.
  • Change a few instances of FloatInt to float | int.
    • statistics._Number
  • Change a few instances of FloatInt to float:
    • time._SupportsFloatOrIndex (is in union with SupportsIndex)
    • builtins.pow (int is handled in earlier overloads, prevents overlapping overloads warning)
    • fractions (same reason)
  • Add int to constraints of statistics._NumberT.
  • Remove # noqa: Y041 comments.
  • Update/remove a few outdated comments.

Part of #16059

Keep `float` in the following cases:

- If it's already in an union with `int`.
- Return types (also in compound return types).
- Return types of `Callable` types.
- Type arguments of base classes.
- Type var constraints.

This was mainly generated using a codemod, and manually verified.
Manual changes:

- Reordered `float`/`int` unions to a consistent order.
- Change a few instances of `FloatInt` to `float | int`.
    - `statistics._Number`
- Change a few instances of `FloatInt` to `float`:
    - `time._SupportsFloatOrIndex` (is in union with `SupportsIndex`)
- Add `int` to constraints of `statistics._NumberT`.
- Remove `# noqa: Y041` comments.
- Update/remove a few outdated comments.

Part of python#16059
@srittau
srittau requested a review from Akuli as a code owner November 13, 2026 15:13
@github-actions

This comment has been minimized.

@srittau srittau mentioned this pull request Nov 13, 2026
3 of 7 tasks
@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/runner/_scheduled_run_poller.py:187: error: Argument "seconds" to "timedelta" has incompatible type "int | None"; expected "float"  [arg-type]
+ src/prefect/runner/_scheduled_run_poller.py:187: error: Argument "seconds" to "timedelta" has incompatible type "int | None"; expected "float | int"  [arg-type]

materialize (https://github.com/MaterializeInc/materialize)
- misc/python/materialize/scratch.py:113: note:     def [_TzInfoT: tzinfo | None] fromtimestamp(cls, timestamp: float, tz: None = ...) -> datetime[None]
+ misc/python/materialize/scratch.py:113: note:     def [_TzInfoT: tzinfo | None] fromtimestamp(cls, timestamp: float | int, tz: None = ...) -> datetime[None]
- misc/python/materialize/scratch.py:113: note:     def [_TzInfoT: tzinfo | None] fromtimestamp(cls, timestamp: float, tz: tzinfo) -> datetime[tzinfo]
+ misc/python/materialize/scratch.py:113: note:     def [_TzInfoT: tzinfo | None] fromtimestamp(cls, timestamp: float | int, tz: tzinfo) -> datetime[tzinfo]
- misc/python/materialize/scratch.py:113: note:     def [_TzInfoT: tzinfo | None] fromtimestamp(cls, timestamp: float, tz: tzinfo | None) -> datetime[tzinfo] | datetime[None]
+ misc/python/materialize/scratch.py:113: note:     def [_TzInfoT: tzinfo | None] fromtimestamp(cls, timestamp: float | int, tz: tzinfo | None) -> datetime[tzinfo] | datetime[None]

ibis (https://github.com/ibis-project/ibis)
- ibis/common/temporal.py:196: error: Argument 1 to "Decimal" has incompatible type "Real"; expected "Decimal | float | str | tuple[int, Sequence[int], int]"  [arg-type]
+ ibis/common/temporal.py:196: error: Argument 1 to "Decimal" has incompatible type "Real"; expected "Decimal | float | int | str | tuple[int, Sequence[int], int]"  [arg-type]

jax (https://github.com/google/jax)
- jax/_src/numpy/indexing.py:370: error: Incompatible types in assignment (expression has type "Array | ndarray[tuple[Any, ...], dtype[Any]] | Any | int | float | complex", variable has type "int | integer[Any] | slice[Any, Any, Any] | EllipsisType | Sequence[int | integer[Any]] | Array | ndarray[tuple[Any, ...], dtype[Any]] | None")  [assignment]
+ jax/_src/numpy/indexing.py:370: error: Incompatible types in assignment (expression has type "Array | ndarray[tuple[Any, ...], dtype[Any]] | signedinteger[_32Bit | _64Bit] | Any | int | float | complex", variable has type "int | integer[Any] | slice[Any, Any, Any] | EllipsisType | Sequence[int | integer[Any]] | Array | ndarray[tuple[Any, ...], dtype[Any]] | None")  [assignment]

pytensor (https://github.com/pymc-devs/pytensor)
- pytensor/tensor/extra_ops.py:1791: note:     def __pow__(self, float, None = ..., /) -> Any
+ pytensor/tensor/extra_ops.py:1791: note:     def __pow__(self, float | int, None = ..., /) -> Any
- pytensor/tensor/extra_ops.py:1867: note:     def __pow__(self, float, None = ..., /) -> Any
+ pytensor/tensor/extra_ops.py:1867: note:     def __pow__(self, float | int, None = ..., /) -> Any

@srittau

srittau commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator Author

Primer output is purely cosmetic.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant