@@ -308,14 +308,7 @@ def is_generator_return_type(self, typ: Type, is_coroutine: bool) -> bool:
308
308
gt = self .named_generic_type ('typing.Generator' , [AnyType (), AnyType (), AnyType ()])
309
309
if is_subtype (gt , typ ):
310
310
return True
311
- # Check that AwaitableGenerator exists -- it isn't defined in Python 2:
312
- try :
313
- self .lookup_qualified ('typing.AwaitableGenerator' )
314
- except KeyError :
315
- return False
316
- agt = self .named_generic_type ('typing.AwaitableGenerator' ,
317
- [AnyType (), AnyType (), AnyType (), AnyType ()])
318
- return is_equivalent (typ , agt )
311
+ return isinstance (typ , Instance ) and typ .type .fullname () == 'typing.AwaitableGenerator'
319
312
320
313
def get_generator_yield_type (self , return_type : Type , is_coroutine : bool ) -> Type :
321
314
"""Given the declared return type of a generator (t), return the type it yields (ty)."""
@@ -342,7 +335,10 @@ def get_generator_yield_type(self, return_type: Type, is_coroutine: bool) -> Typ
342
335
return Void ()
343
336
return ret_type
344
337
else :
345
- # object: ty is Any.
338
+ # If the function's declared supertype of Generator has no type
339
+ # parameters (i.e. is `object`), then the yielded values can't
340
+ # be accessed so any type is acceptable. IOW, ty is Any.
341
+ # (However, see https://github.com/python/mypy/issues/1933)
346
342
return AnyType ()
347
343
348
344
def get_generator_receive_type (self , return_type : Type , is_coroutine : bool ) -> Type :
@@ -364,7 +360,8 @@ def get_generator_receive_type(self, return_type: Type, is_coroutine: bool) -> T
364
360
# Generator: tc is args[1].
365
361
return return_type .args [1 ]
366
362
else :
367
- # Supertype of Generator (Iterator, Iterable, object), tc is None.
363
+ # `return_type` is a supertype of Generator, so callers won't be able to send it
364
+ # values. IOW, tc is None.
368
365
if experiments .STRICT_OPTIONAL :
369
366
return NoneTyp (is_ret_type = True )
370
367
else :
0 commit comments