-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Phase 2 of async/await #1946
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
Phase 2 of async/await #1946
Conversation
520a431
to
d0f7a5e
Compare
@@ -61,6 +62,9 @@ class Awaitable(Generic[T]): | |||
@abstractmethod | |||
def __await__(self) -> Generator[Any, Any, T]: pass | |||
|
|||
class AwaitableGenerator(Generator[T, U, V], Awaitable[V], Generic[T, U, V, S]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is there an AwaitableGenerator
in the test data typing
stub when there isn't one in the real typing
module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this stub (despite its extension) is actually a stub. It matches the real typing.pyi
, not any real typing.py
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh okay. That makes sense.
30e1a4a
to
77f2ba2
Compare
self.lookup_qualified('typing.AwaitableGenerator') | ||
except KeyError: | ||
return False | ||
agt = self.named_generic_type('typing.AwaitableGenerator', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be simpler to just look at the fullname instead, like we do elsewhere?
Both crawl.py and crawl2.py pass cleanly now!
else: | ||
# `return_type` is a supertype of Generator, so callers won't be able to send it | ||
# values. | ||
# Supertype of Generator (Iterator, Iterable, object), tc is None. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the bit of motivation is worthwhile here too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly streamlined the comments, but also decided that return in a generator not explicitly declared as returning Any or Generator should be None.
NOTE: the Matrix test is currently failing.
Upgrade AwaitableGenerator to four parameters -- the last one preserves the original type, which we sometimes need.
77f2ba2
to
839dc7d
Compare
🎉 |
This PR adds support for decorating either generators or
async def
functions with@types.coroutine
or@asyncio.coroutine
. This will fix #1453.