File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -859,6 +859,7 @@ class B: pass
859
859
-- Type aliases
860
860
-- ------------
861
861
862
+
862
863
[case testSimpleTypeAlias]
863
864
import typing
864
865
foo = int
@@ -885,3 +886,52 @@ f('x') # E: Argument 1 to "f" has incompatible type "str"; expected "int"
885
886
[file m.py]
886
887
import typing
887
888
foo = int
889
+
890
+
891
+ -- nonlocal and global
892
+ -- -------------------
893
+
894
+
895
+ [case testTypeOfGlobalUsed]
896
+ import typing
897
+ g = A()
898
+ def f() -> None:
899
+ global g
900
+ g = B()
901
+
902
+ class A(): pass
903
+ class B(): pass
904
+ [out]
905
+ main: In function "f":
906
+ main, line 5: Incompatible types in assignment (expression has type "B", variable has type "A")
907
+
908
+ [case testTypeOfNonlocalUsed]
909
+ import typing
910
+ def f() -> None:
911
+ a = A()
912
+ def g() -> None:
913
+ nonlocal a
914
+ a = B()
915
+
916
+ class A(): pass
917
+ class B(): pass
918
+ [out]
919
+ main: In function "g":
920
+ main, line 6: Incompatible types in assignment (expression has type "B", variable has type "A")
921
+
922
+ [case testTypeOfOuterMostNonlocalUsed]
923
+ import typing
924
+ def f() -> None:
925
+ a = A()
926
+ def g() -> None:
927
+ a = B()
928
+ def h() -> None:
929
+ nonlocal a
930
+ a = A()
931
+ a = B()
932
+
933
+ class A(): pass
934
+ class B(): pass
935
+ [out]
936
+ main: In function "h":
937
+ main, line 8: Incompatible types in assignment (expression has type "A", variable has type "B")
You can’t perform that action at this time.
0 commit comments