Skip to content

stubtest: error if a function is async at runtime but not in the stub (and vice versa) #12212

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

Merged
merged 2 commits into from
Feb 19, 2022

Conversation

AlexWaygood
Copy link
Member

Description

Stubtest does not currently error if a function is async at runtime, but not in the stub (or vice versa). This PR fixes that!

This is an attempt at implementing a regression test for these typeshed PRs:

cc. @hauntsaninja

Test Plan

I've added four test cases. Note that the test file needed a bit of rejigging, as Coroutine wasn't defined in the stub for typing that teststubtest was using.

The changes in this PR generate three hits when checking typeshed. I'm not sure if they're true positives or not tbh:

error: types.AsyncGeneratorType.__anext__ is a coroutine function in the stub, but not at runtime
Stub: at line 239
def (self: types.AsyncGeneratorType[_T_co`1, _T_contra`2]) -> typing.Coroutine[Any, Any, _T_co`1]
Runtime:
def (self, /)

error: types.AsyncGeneratorType.aclose is a coroutine function in the stub, but not at runtime
Stub: at line 247
def (self: types.AsyncGeneratorType[_T_co`1, _T_contra`2]) -> typing.Coroutine[Any, Any, None]
Runtime:
<method 'aclose' of 'async_generator' objects>

error: types.AsyncGeneratorType.asend is a coroutine function in the stub, but not at runtime
Stub: at line 240
def (self: types.AsyncGeneratorType[_T_co`1, _T_contra`2], _T_contra`2) -> typing.Coroutine[Any, Any, _T_co`1]
Runtime:
<method 'asend' of 'async_generator' objects>

@github-actions

This comment has been minimized.

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Thanks!

Error message nit: maybe is an "async def" in the stub, but not at runtime could be clearer? While "coroutine function" is true to the inspect call, I think it's less obvious.

@hauntsaninja
Copy link
Collaborator

The hooray for the mypy_primer is cute, but it would be quite unfortunate if stubtest ever did a thing to affect mypy_primer :D

@AlexWaygood
Copy link
Member Author

The hooray for the mypy_primer is cute, but it would be quite unfortunate if stubtest ever did a thing to affect mypy_primer :D

Well, obviously :P

@github-actions
Copy link
Contributor

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

@hauntsaninja hauntsaninja merged commit 85fc99c into python:master Feb 19, 2022
@AlexWaygood
Copy link
Member Author

Thanks! :D

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