@@ -308,14 +308,7 @@ def is_generator_return_type(self, typ: Type, is_coroutine: bool) -> bool:
308308 gt = self .named_generic_type ('typing.Generator' , [AnyType (), AnyType (), AnyType ()])
309309 if is_subtype (gt , typ ):
310310 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'
319312
320313 def get_generator_yield_type (self , return_type : Type , is_coroutine : bool ) -> Type :
321314 """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
342335 return Void ()
343336 return ret_type
344337 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)
346342 return AnyType ()
347343
348344 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
364360 # Generator: tc is args[1].
365361 return return_type .args [1 ]
366362 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.
368365 if experiments .STRICT_OPTIONAL :
369366 return NoneTyp (is_ret_type = True )
370367 else :
0 commit comments