File tree 2 files changed +37
-3
lines changed
2 files changed +37
-3
lines changed Original file line number Diff line number Diff line change @@ -889,9 +889,13 @@ def is_unannotated_any(t: Type) -> bool:
889
889
ret_type = fdef .type .ret_type
890
890
if is_unannotated_any (ret_type ):
891
891
self .fail (messages .RETURN_TYPE_EXPECTED , fdef )
892
- elif (fdef .is_coroutine and isinstance (ret_type , Instance ) and
893
- is_unannotated_any (self .get_coroutine_return_type (ret_type ))):
894
- self .fail (messages .RETURN_TYPE_EXPECTED , fdef )
892
+ elif fdef .is_generator :
893
+ if is_unannotated_any (self .get_generator_return_type (ret_type ,
894
+ fdef .is_coroutine )):
895
+ self .fail (messages .RETURN_TYPE_EXPECTED , fdef )
896
+ elif fdef .is_coroutine and isinstance (ret_type , Instance ):
897
+ if is_unannotated_any (self .get_coroutine_return_type (ret_type )):
898
+ self .fail (messages .RETURN_TYPE_EXPECTED , fdef )
895
899
if any (is_unannotated_any (t ) for t in fdef .type .arg_types ):
896
900
self .fail (messages .ARGUMENT_TYPE_EXPECTED , fdef )
897
901
Original file line number Diff line number Diff line change @@ -669,3 +669,33 @@ async def decorated_host_coroutine() -> None:
669
669
[builtins fixtures/async_await.pyi]
670
670
[typing fixtures/typing-full.pyi]
671
671
[out]
672
+
673
+ [case testAsyncGenDisallowUntyped]
674
+ # flags: --disallow-untyped-defs
675
+ # These should not crash
676
+ from typing import AsyncGenerator, Any
677
+
678
+ async def f() -> AsyncGenerator[int, None]:
679
+ yield 0
680
+
681
+ async def g() -> AsyncGenerator[Any, None]:
682
+ yield 0
683
+ [builtins fixtures/async_await.pyi]
684
+ [typing fixtures/typing-full.pyi]
685
+ [out]
686
+
687
+ [case testAsyncGenDisallowUntypedTriggers]
688
+ # flags: --disallow-untyped-defs
689
+ from typing import AsyncGenerator, Any
690
+
691
+ async def f() -> AsyncGenerator[Any, Any]:
692
+ yield None
693
+
694
+ async def h() -> Any:
695
+ yield 0
696
+
697
+ async def g(): # E: Function is missing a type annotation
698
+ yield 0
699
+ [builtins fixtures/async_await.pyi]
700
+ [typing fixtures/typing-full.pyi]
701
+ [out]
You can’t perform that action at this time.
0 commit comments