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

Update stubtest for async and dunder pos only checking #7333

Merged
merged 6 commits into from
Feb 21, 2022

Conversation

hauntsaninja
Copy link
Collaborator

No description provided.

@github-actions

This comment has been minimized.

@@ -236,15 +236,15 @@ class AsyncGeneratorType(AsyncGenerator[_T_co, _T_contra]):
__name__: str
__qualname__: str
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
Member

Choose a reason for hiding this comment

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

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

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
Member

Choose a reason for hiding this comment

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

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

Copy link
Member

Choose a reason for hiding this comment

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

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(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
Member

Choose a reason for hiding this comment

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

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!

@JelleZijlstra
Copy link
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
Copy link
Member

AlexWaygood commented Feb 21, 2022

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.

@github-actions

This comment has been minimized.

Comment on lines 6 to 7
asyncio.AbstractEventLoop.run_in_executor
asyncio.events.AbstractEventLoop.run_in_executor
Copy link
Member

@AlexWaygood AlexWaygood Feb 21, 2022

Choose a reason for hiding this comment

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

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

Copy link
Collaborator Author

@hauntsaninja hauntsaninja Feb 21, 2022

Choose a reason for hiding this comment

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

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
Member

Choose a reason for hiding this comment

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

Okay, fair enough!

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we could add a comment to that effect?

@github-actions

This comment has been minimized.

3 similar comments
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

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

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

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

@AlexWaygood
Copy link
Member

AlexWaygood commented Feb 22, 2022

@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.

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