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 @@ -929,9 +929,13 @@ def is_unannotated_any(t: Type) -> bool:
929
929
ret_type = fdef .type .ret_type
930
930
if is_unannotated_any (ret_type ):
931
931
self .fail (messages .RETURN_TYPE_EXPECTED , fdef )
932
- elif (fdef .is_coroutine and isinstance (ret_type , Instance ) and
933
- is_unannotated_any (self .get_coroutine_return_type (ret_type ))):
934
- self .fail (messages .RETURN_TYPE_EXPECTED , fdef )
932
+ elif fdef .is_generator :
933
+ if is_unannotated_any (self .get_generator_return_type (ret_type ,
934
+ fdef .is_coroutine )):
935
+ self .fail (messages .RETURN_TYPE_EXPECTED , fdef )
936
+ elif fdef .is_coroutine and isinstance (ret_type , Instance ):
937
+ if is_unannotated_any (self .get_coroutine_return_type (ret_type )):
938
+ self .fail (messages .RETURN_TYPE_EXPECTED , fdef )
935
939
if any (is_unannotated_any (t ) for t in fdef .type .arg_types ):
936
940
self .fail (messages .ARGUMENT_TYPE_EXPECTED , fdef )
937
941
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