Skip to content

Conversation

@gvanrossum
Copy link
Member

This PR adds support for decorating either generators or async def functions with @types.coroutine or @asyncio.coroutine. This will fix #1453.

@abstractmethod
def __await__(self) -> Generator[Any, Any, T]: pass

class AwaitableGenerator(Generator[T, U, V], Awaitable[V], Generic[T, U, V, S]):
Copy link
Collaborator

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?

Copy link
Member Author

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.

Copy link
Collaborator

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.

mypy/checker.py Outdated
self.lookup_qualified('typing.AwaitableGenerator')
except KeyError:
return False
agt = self.named_generic_type('typing.AwaitableGenerator',
Copy link
Collaborator

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?

mypy/checker.py Outdated
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.
Copy link
Collaborator

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

@ddfisher ddfisher merged commit 340d34e into master Aug 3, 2016
@ddfisher ddfisher deleted the add-crawl2-reborn branch August 3, 2016 23:57
@ddfisher
Copy link
Collaborator

ddfisher commented Aug 3, 2016

🎉

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.

Support PEP 492 syntax

3 participants