Skip to content

Mark several asyncio modules as Windows-only#6796

Merged
srittau merged 6 commits into
python:masterfrom
sobolevn:asyncio-win-only
Jan 3, 2022
Merged

Mark several asyncio modules as Windows-only#6796
srittau merged 6 commits into
python:masterfrom
sobolevn:asyncio-win-only

Conversation

@sobolevn

@sobolevn sobolevn commented Jan 3, 2022

Copy link
Copy Markdown
Member

@github-actions

This comment has been minimized.

Comment thread stdlib/concurrent/futures/_base.pyi Outdated
class Executor:
if sys.version_info >= (3, 9):
def submit(self, __fn: Callable[..., _T], *args: Any, **kwargs: Any) -> Future[_T]: ...
def submit(self, __fn: Callable[_P, _T], *args: _P.args, **kwargs: _P.kwargs) -> Future[_T]: ...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated, sorry. I will remove it shortly.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@sobolevn

sobolevn commented Jan 3, 2022

Copy link
Copy Markdown
Member Author

Ok, looks like the order of mypy_primer output is broken. It seems like this #6796 (comment) is the last one.

@sobolevn

sobolevn commented Jan 3, 2022

Copy link
Copy Markdown
Member Author

I will try to reopen this PR.

@sobolevn sobolevn closed this Jan 3, 2022
@sobolevn sobolevn reopened this Jan 3, 2022
@github-actions

github-actions Bot commented Jan 3, 2022

Copy link
Copy Markdown
Contributor

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

@sobolevn

sobolevn commented Jan 3, 2022

Copy link
Copy Markdown
Member Author

Yeap, I was right 🙂

@srittau srittau left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These files exist on Linux at least and have all definitions. I don't think we should guard this behind platform checks, even if this doesn't work on non-Windows platforms. For example, I wouldn't want code like the following, which works at runtime, fail during typecheck:

from asyncio.unix_events import SelectorEventLoop
from asyncio.windows_events import ProactorEventLoop

if sys.platform == "win32":
    loop = ProactorEventLoop
else:
    loop = SelectorEventLoop

@sobolevn

sobolevn commented Jan 3, 2022

Copy link
Copy Markdown
Member Author

which works at runtime, fail during typecheck:

This code does not work in runtime. It fails with ImportError.

Explicit check for windows_utils: https://github.com/python/cpython/blob/main/Lib/asyncio/windows_utils.py#L5
For windows_events it fails because import _winapi fails with ImportError, refs python/cpython#30353

So, typechecking is correct here. It should be:

if sys.platform == "win32":
    from asyncio.windows_events import ProactorEventLoop
    loop = ProactorEventLoop
else:
    from asyncio.unix_events import SelectorEventLoop
    loop = SelectorEventLoop

@srittau
srittau merged commit 6e45c31 into python:master Jan 3, 2022
@sobolevn

sobolevn commented Jan 3, 2022

Copy link
Copy Markdown
Member Author

@srittau thank you! 🙂

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.

2 participants