8000 Implement async generators (PEP 525) by JelleZijlstra · Pull Request #2711 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Implement async generators (PEP 525) #2711

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 11 commits into from
Mar 18, 2017
Prev Previous commit
Next Next commit
remove AsyncGenerator from mypy_extensions
Probably not worth it
  • Loading branch information
JelleZijlstra committed Mar 18, 2017
commit feaf0512833f4be274621135fa79c20de5adb67e
24 changes: 0 additions & 24 deletions extensions/mypy_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,12 @@
"""

# NOTE: This module must support Python 2.7 in addition to Python 3.x
__all__ = ['TypedDict', 'AsyncGenerator']

import sys
# _type_check is NOT a part of public typing API, it is used here only to mimic
# the (convenient) behavior of types provided by typing module.
from typing import _type_check # type: ignore

if sys.version_info >= (3, 6):
# if our typing version doesn't have https://github.com/python/typing/pull/346, emulate it
try:
from typing import AsyncGenerator
except ImportError:
import collections
from typing import AsyncIterator, Generic, _generic_new, T_co, T_contra

_AG_base = collections.AsyncGenerator

# need exec because the class keyword arg is a syntax error in 2.7
exec("""
class AsyncGenerator(AsyncIterator[T_co], Generic[T_co, T_contra],
extra=_AG_base):
__slots__ = ()

def __new__(cls, *args, **kwds):
if _geqv(cls, AsyncGenerator):
raise TypeError("Type AsyncGenerator cannot be instantiated; "
"create a subclass instead")
return _generic_new(_AG_base, cls, *args, **kwds)
""")


def _check_fails(cls, other):
try:
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/lib-stub/mypy_extensions.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, Type, TypeVar, AsyncGenerator as AsyncGenerator
from typing import Dict, Type, TypeVar

T = TypeVar('T')

Expand Down
0