Skip to content

Commit f155c65

Browse files
committed
fix lint and make it crash less often on typing without AsyncGenerator
1 parent cc54632 commit f155c65

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

mypy/checker.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,11 @@ def is_async_generator_return_type(self, typ: Type) -> bool:
374374
375375
True if `typ` is a supertype of AsyncGenerator.
376376
"""
377-
agt = self.named_generic_type('typing.AsyncGenerator', [AnyType(), AnyType()])
377+
try:
378+
agt = self.named_generic_type('typing.AsyncGenerator', [AnyType(), AnyType()])
379+
except KeyError:
380+
# we're running on a version of typing that doesn't have AsyncGenerator yet
381+
return False
378382
return is_subtype(agt, typ)
379383

380384
def get_generator_yield_type(self, return_type: Type, is_coroutine: bool) -> Type:

mypy/messages.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
INVALID_RETURN_TYPE_FOR_GENERATOR = \
3232
'The return type of a generator function should be "Generator" or one of its supertypes'
3333
INVALID_RETURN_TYPE_FOR_ASYNC_GENERATOR = \
34-
'The return type of an async generator function should be "AsyncGenerator" or one of its supertypes'
34+
'The return type of an async generator function should be "AsyncGenerator" or one of its ' \
35+
'supertypes'
3536
INVALID_GENERATOR_RETURN_ITEM_TYPE = \
3637
'The return type of a generator function must be None in its third type parameter in Python 2'
3738
YIELD_VALUE_EXPECTED = 'Yield value expected'

0 commit comments

Comments
 (0)