Skip to content

Conversation

@Dutcho
Copy link
Contributor

@Dutcho Dutcho commented Jan 24, 2026

Change accepted parameter type of sleep and other functions to fix #15313

This changes to:

def ctime(seconds: _SupportsFloatOrIndex | None = None, /) -> str: ...
def gmtime(seconds: _SupportsFloatOrIndex | None = None, /) -> struct_time: ...
def localtime(seconds: _SupportsFloatOrIndex | None = None, /) -> struct_time: ...
def sleep(seconds: _SupportsFloatOrIndex, /) -> None: ...

For Python <= 3.14, _SupportsFloatOrIndex is a little white lie: It aliases float | SupportsIndex. However, that prepares for Python >= 3.15, when it will correctly name the alias.

@github-actions

This comment has been minimized.

@Dutcho
Copy link
Contributor Author

Dutcho commented Jan 24, 2026

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

prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/deployments/flow_runs.py:441: error: Argument 1 to "sleep" has incompatible type "float | None"; expected "float"  [arg-type]
+ src/prefect/deployments/flow_runs.py:441: error: Argument 1 to "sleep" has incompatible type "float | None"; expected "float | SupportsIndex"  [arg-type]

I'd consider this diff as by intent.

@github-actions
Copy link
Contributor

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

prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/deployments/flow_runs.py:441: error: Argument 1 to "sleep" has incompatible type "float | None"; expected "float"  [arg-type]
+ src/prefect/deployments/flow_runs.py:441: error: Argument 1 to "sleep" has incompatible type "float | None"; expected "float | SupportsIndex"  [arg-type]

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.

time.sleep() type should reflect actually accepted parameters

1 participant