Skip to content

AsyncIterator.__anext__ can be any Awaitable object #7475

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

Closed
wants to merge 1 commit into from

Conversation

graingert
Copy link
Contributor

@graingert
Copy link
Contributor Author

I think this also applies to AsyncGenerator

@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

tornado (https://github.com/tornadoweb/tornado)
- tornado/gen.py:429: error: Incompatible return value type (got "WaitIterator", expected "AsyncIterator[Any]")
- tornado/gen.py:429: note: Following member(s) of "WaitIterator" have conflicts:
- tornado/gen.py:429: note:     Expected:
- tornado/gen.py:429: note:         def __anext__(self) -> Coroutine[Any, Any, Any]
- tornado/gen.py:429: note:     Got:
- tornado/gen.py:429: note:         def __anext__(self) -> Future[Any]

boostedblob (https://github.com/hauntsaninja/boostedblob)
+ boostedblob/boost.py:547: error: Need type annotation for "task"
+ boostedblob/boost.py:547: error: Argument 1 to "create_task" has incompatible type "Awaitable[T]"; expected "Union[Generator[Any, None, <nothing>], Coroutine[Any, Any, <nothing>]]"

@graingert
Copy link
Contributor Author

Yep they're all specified as returning Awaitable:

https://peps.python.org/pep-0525/#asynchronous-generator-object

I think this PR needs reverting #7105

@AlexWaygood
Copy link
Member

AlexWaygood commented Mar 13, 2022

I think this PR needs reverting #7105

Yes, I think that's probably right. stubtest is complaining because these are all async def functions at runtime (but wouldn't be in the stub with this PR merged), but the return type for abstract interfaces should be as broad as possible. I've filed python/mypy#12343 to relax that stubtest check.

@graingert
Copy link
Contributor Author

It would be nice if "real" async def agenfn(...): ... yield had a stricter type which did have Coroutine asend/aclose

@AlexWaygood
Copy link
Member

It would be nice if "real" async def agenfn(...): ... yield had a stricter type which did have Coroutine asend/aclose

Not sure I understand, sorry

@AlexWaygood
Copy link
Member

I've proposed a slightly larger PR here: #7491. Would appreciate your thoughts!

@graingert
Copy link
Contributor Author

It would be nice if "real" async def agenfn(...): ... yield had a stricter type which did have Coroutine asend/aclose

Not sure I understand, sorry

Oh this already exists as types.AsyncGeneratorType

@graingert graingert closed this Mar 14, 2022
@graingert graingert deleted the patch-2 branch March 14, 2022 18:46
@graingert
Copy link
Contributor Author

Closing in favour of #7491

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