FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Update stubtest for async and dunder pos only checking by hauntsaninja · Pull Request #7333 · python/typeshed · GitHub

Repository navigation

Update stubtest for async and dunder pos only checking - #7333

Merged
hauntsaninja merged 6 commits into
python:masterfrom
hauntsaninja:stubas
Feb 21, 2022
Merged

hauntsaninja merged 6 commits into
python:masterfrom
hauntsaninja:stubas

Conversation

Copy link
Copy Markdown
Collaborator

No description provided.

This comment has been minimized.

Comment thread stdlib/types.pyi
def __aiter__(self) -> AsyncGeneratorType[_T_co, _T_contra]: ...
async def __anext__(self) -> _T_co: ...
async def asend(self, __val: _T_contra) -> _T_co: ...
def __anext__(self) -> Coroutine[Any, Any, _T_co]: ...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Out of curiosity, what is the reason for these changes?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Well,

>>> inspect.iscoroutinefunction(types.AsyncGeneratorType.aclose)
False

I'm not sure if this matters at all, cc @AlexWaygood who added this to stubtest.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

cc. @AlexWaygood who made them async only a few weeks ago as well...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

"Classes" in the types module are weird, I'm happy to go with whatever stubtest thinks best personally.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

(the other big change we've made recently is switching a lot of (...) -> Awaitable into async (...) -> which actually does make a difference to type checking)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Interestingly, it looks like there are already at least 2 open BPO issues about the fact that inspect.iscoroutinefunction returns False for types.AsyncGeneratorType.__anext__, .asend and .aclose. https://bugs.python.org/issue42760.

I'm not really sure what we should make of that, but it's interesting!

Copy link
Copy Markdown
Member

There are also a ton of new stubtest failures on 3.6 and 3.7, probably because they were using @asyncio.coroutine instead of async def at the time. I think we should just ignore those, similar to how we ignore positional-only discrepancies in old versions.

AlexWaygood commented Feb 21, 2022 •
edited
Loading

Copy link
Copy Markdown
Member

There are also a ton of new stubtest failures on 3.6 and 3.7, probably because they were using @asyncio.coroutine instead of async def at the time. I think we should just ignore those, similar to how we ignore positional-only discrepancies in old versions.

The 3.7 ones look like true positives to me, and it doesn't look like there's too many. But yeah, it would maybe be good to have a command-line option to switch the async check off, so that we don't have a bajillion false positives when checking 3.6.

Comment thread tests/stubtest_allowlists/py36.txt Outdated

This comment has been minimized.

Comment thread tests/stubtest_allowlists/py37.txt Outdated
Comment on lines +6 to +7
asyncio.AbstractEventLoop.run_in_executor
asyncio.events.AbstractEventLoop.run_in_executor

AlexWaygood Feb 21, 2022 •
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This is a true positive -- it's async in the 3.7 branch of CPython; it was changed to be a synchronous method in 3.8. I think we should fix the stub rather than adding it to the allowlist. https://github.com/python/cpython/blob/811f65ba263140b6ba28151246b52efe149a6382/Lib/asyncio/events.py#L289

hauntsaninja Feb 21, 2022 •
edited
Loading

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think we should still allowlist it. If you've implemented the AbstractEventLoop interface, you probably don't want some type checker yelling at you for returning a Future (if you check with 3.7).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Okay, fair enough!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Maybe we could add a comment to that effect?

This comment has been minimized.

3 similar comments

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

Copy link
Copy Markdown
Contributor

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

hauntsaninja merged commit 075b8e0 into python:master Feb 21, 2022
hauntsaninja deleted the stubas branch February 21, 2022 23:54

Copy link
Copy Markdown
Collaborator Author

Hopefully just in time for the daily test to tell us if this causes issues with third party stubs :-)

AlexWaygood commented Feb 22, 2022 •
edited
Loading

Copy link
Copy Markdown
Member

@hauntsaninja, would you be up for trying this again now that #7352 is merged? The aiofiles hits would have to be allowlisted for now until python/mypy#12234 is in, but the other hits should be resolved now.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

3 participants


Back | FazBrowse Home | New Git URL