Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add overloads for asyncio.sleep(). #7873

Merged
merged 3 commits into from
May 18, 2022
Merged

Conversation

wch
Copy link
Contributor

@wch wch commented May 18, 2022

Closes #7866. This adds an overload to asyncio.sleep(), so that when it is called without return=None, the type checker knows that the return type is None instead of unknown.

Also related to microsoft/pyright#3475.

stdlib/asyncio/tasks.pyi Outdated Show resolved Hide resolved
stdlib/asyncio/tasks.pyi Outdated Show resolved Hide resolved
@github-actions

This comment has been minimized.

@wch
Copy link
Contributor Author

wch commented May 18, 2022

Looking for a bit of advice. This part fails the CI checks on Python <= 3.9. (Python >= 3.10 uses a different code path which seems to be fine.)

    @overload
    async def sleep(delay: float, *, loop: AbstractEventLoop | None = ...) -> None: ...
    @overload
    async def sleep(delay: float, result: _T = ..., *, loop: AbstractEventLoop | None = ...) -> _T: ...
stdlib/asyncio/tasks.pyi:288: error: Overloaded function signatures 1 and 2 overlap with incompatible return types  [misc]

Is it possible to make this work?

@AlexWaygood
Copy link
Member

Is it possible to make this work?

Committing @JelleZijlstra's suggestions he made in review just now should do it :)

Co-authored-by: Jelle Zijlstra <[email protected]>
@wch
Copy link
Contributor Author

wch commented May 18, 2022

@AlexWaygood Thanks, he must have posted that as I was typing. :)

@github-actions

This comment has been minimized.

1 similar comment
@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JelleZijlstra JelleZijlstra merged commit 6653be1 into python:master May 18, 2022
@wch wch deleted the fix-sleep-type branch May 19, 2022 14:42
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.

asyncio.sleep() should have an overload
3 participants