@@ -863,6 +863,146 @@ def g(): pass
863
863
def dec(f): pass
864
864
865
865
866
+ -- Decorator functions in import cycles
867
+ -- ------------------------------------
868
+
869
+
870
+ [case testDecoratorWithIdentityTypeInImportCycle]
871
+ import a
872
+
873
+ [file a.py]
874
+ import b
875
+ from d import dec
876
+ @dec
877
+ def f(x: int) -> None: pass
878
+ b.g(1) # E
879
+
880
+ [file b.py]
881
+ import a
882
+ from d import dec
883
+ @dec
884
+ def g(x: str) -> None: pass
885
+ a.f('')
886
+
887
+ [file d.py]
888
+ from typing import TypeVar
889
+ T = TypeVar('T')
890
+ def dec(f: T) -> T: return f
891
+
892
+ [out]
893
+ tmp/a.py:1: note: In module imported here,
894
+ main:1: note: ... from here:
895
+ tmp/b.py:5: error: Argument 1 to "f" has incompatible type "str"; expected "int"
896
+ main:1: note: In module imported here:
897
+ tmp/a.py:5: error: Argument 1 to "g" has incompatible type "int"; expected "str"
898
+
899
+ [case testDecoratorWithNoAnnotationInImportCycle]
900
+ import a
901
+
902
+ [file a.py]
903
+ import b
904
+ from d import dec
905
+ @dec
906
+ def f(x: int) -> None: pass
907
+ b.g(1, z=4)
908
+
909
+ [file b.py]
910
+ import a
911
+ from d import dec
912
+ @dec
913
+ def g(x: str) -> None: pass
914
+ a.f('', y=2)
915
+
916
+ [file d.py]
917
+ def dec(f): return f
918
+
919
+ [case testDecoratorWithFixedReturnTypeInImportCycle]
920
+ import a
921
+
922
+ [file a.py]
923
+ import b
924
+ from d import dec
925
+ @dec
926
+ def f(x: int) -> str: pass
927
+ b.g(1)()
928
+
929
+ [file b.py]
930
+ import a
931
+ from d import dec
932
+ @dec
933
+ def g(x: int) -> str: pass
934
+ a.f(1)()
935
+
936
+ [file d.py]
937
+ from typing import Callable
938
+ def dec(f: Callable[[int], str]) -> Callable[[int], str]: return f
939
+
940
+ [out]
941
+ tmp/a.py:1: note: In module imported here,
942
+ main:1: note: ... from here:
943
+ tmp/b.py:5: error: "str" not callable
944
+ main:1: note: In module imported here:
945
+ tmp/a.py:5: error: "str" not callable
946
+
947
+ [case testDecoratorWithCallAndFixedReturnTypeInImportCycle]
948
+ import a
949
+
950
+ [file a.py]
951
+ import b
952
+ from d import dec
953
+ @dec()
954
+ def f(x: int) -> str: pass
955
+ b.g(1)()
956
+
957
+ [file b.py]
958
+ import a
959
+ from d import dec
960
+ @dec()
961
+ def g(x: int) -> str: pass
962
+ a.f(1)()
963
+
964
+ [file d.py]
965
+ from typing import Callable
966
+ def dec() -> Callable[[Callable[[int], str]], Callable[[int], str]]: pass
967
+
968
+ [out]
969
+ tmp/a.py:1: note: In module imported here,
970
+ main:1: note: ... from here:
971
+ tmp/b.py:5: error: "str" not callable
972
+ main:1: note: In module imported here:
973
+ tmp/a.py:5: error: "str" not callable
974
+
975
+ [case testDecoratorWithCallAndFixedReturnTypeInImportCycleAndDecoratorArgs]
976
+ import a
977
+
978
+ [file a.py]
979
+ import b
980
+ from d import dec
981
+ @dec(1)
982
+ def f(x: int) -> str: pass
983
+ b.g(1)()
984
+
985
+ [file b.py]
986
+ import a
987
+ from d import dec
988
+ @dec(1)
989
+ def g(x: int) -> str: pass
990
+ a.f(1)()
991
+
992
+ [file d.py]
993
+ from typing import Callable
994
+ def dec(x: str) -> Callable[[Callable[[int], str]], Callable[[int], str]]: pass
995
+
996
+ [out]
997
+ tmp/a.py:1: note: In module imported here,
998
+ main:1: note: ... from here:
999
+ tmp/b.py:3: error: Argument 1 to "dec" has incompatible type "int"; expected "str"
1000
+ tmp/b.py:5: error: "str" not callable
1001
+ main:1: note: In module imported here:
1002
+ tmp/a.py:3: error: Argument 1 to "dec" has incompatible type "int"; expected "str"
1003
+ tmp/a.py:5: error: "str" not callable
1004
+
1005
+
866
1006
-- Conditional function definition
867
1007
-- -------------------------------
868
1008
0 commit comments