@@ -191,7 +191,7 @@ main:3: error: "A" has no attribute "x"
191191[case testVariableTypeBecomesInvalid]
192192import m
193193def f() -> None:
194- a = None # type : m.A
194+ a: m.A
195195[file m.py]
196196class A: pass
197197[file m.py.2]
@@ -1724,15 +1724,15 @@ f = 1
17241724main:1: error: Module "a" has no attribute "f"
17251725
17261726[case testDecoratedMethodRefresh]
1727- from typing import Iterator, Callable, List
1727+ from typing import Iterator, Callable, List, Optional
17281728from a import f
17291729import a
17301730
1731- def dec(f: Callable[['A'], Iterator[int]]) -> Callable[[int], int]: pass
1731+ def dec(f: Callable[['A'], Optional[ Iterator[int] ]]) -> Callable[[int], int]: pass
17321732
17331733class A:
17341734 @dec
1735- def f(self) -> Iterator[int]:
1735+ def f(self) -> Optional[ Iterator[int] ]:
17361736 self.x = a.g() # type: int
17371737 return None
17381738[builtins fixtures/list.pyi]
@@ -4626,6 +4626,7 @@ class User:
46264626==
46274627
46284628[case testNoStrictOptionalModule]
4629+ # flags: --no-strict-optional
46294630import a
46304631a.y = a.x
46314632[file a.py]
@@ -4643,9 +4644,10 @@ y: int
46434644[out]
46444645==
46454646==
4646- main:2 : error: Incompatible types in assignment (expression has type "Optional[str]", variable has type "int")
4647+ main:3 : error: Incompatible types in assignment (expression has type "Optional[str]", variable has type "int")
46474648
46484649[case testNoStrictOptionalFunction]
4650+ # flags: --no-strict-optional
46494651import a
46504652from typing import Optional
46514653def f() -> None:
@@ -4666,9 +4668,10 @@ def g(x: str) -> None:
46664668[out]
46674669==
46684670==
4669- main:5 : error: Argument 1 to "g" has incompatible type "Optional[int]"; expected "str"
4671+ main:6 : error: Argument 1 to "g" has incompatible type "Optional[int]"; expected "str"
46704672
46714673[case testNoStrictOptionalMethod]
4674+ # flags: --no-strict-optional
46724675import a
46734676from typing import Optional
46744677class C:
@@ -4693,7 +4696,7 @@ class B:
46934696[out]
46944697==
46954698==
4696- main:6 : error: Argument 1 to "g" of "B" has incompatible type "Optional[int]"; expected "str"
4699+ main:7 : error: Argument 1 to "g" of "B" has incompatible type "Optional[int]"; expected "str"
46974700
46984701[case testStrictOptionalModule]
46994702# flags: --strict-optional
@@ -5276,10 +5279,11 @@ class I(metaclass=ABCMeta):
52765279 @abstractmethod
52775280 def f(self) -> None: pass
52785281[file b.py]
5282+ from typing import Optional
52795283from z import I
52805284class Foo(I):
52815285 pass
5282- def x() -> Foo: return None
5286+ def x() -> Optional[ Foo] : return None
52835287[file z.py.2]
52845288from abc import abstractmethod, ABCMeta
52855289class I(metaclass=ABCMeta):
@@ -5301,10 +5305,11 @@ class I(metaclass=ABCMeta):
53015305 @abstractmethod
53025306 def f(self) -> None: pass
53035307[file b.py]
5308+ from typing import Optional
53045309from a import I
53055310class Foo(I):
53065311 pass
5307- def x() -> Foo: return None
5312+ def x() -> Optional[ Foo] : return None
53085313[file a.py.2]
53095314from abc import abstractmethod, ABCMeta
53105315class I(metaclass=ABCMeta):
@@ -7769,7 +7774,8 @@ from typing import List
77697774import b
77707775class A(b.B):
77717776 def meth(self) -> None:
7772- self.x, *self.y = None, None # type: str, List[str]
7777+ self.x: str
7778+ self.y: List[str]
77737779[file b.py]
77747780from typing import List
77757781class B:
@@ -7781,7 +7787,7 @@ class B:
77817787[builtins fixtures/list.pyi]
77827788[out]
77837789==
7784- main:5 : error: Incompatible types in assignment (expression has type "List[str]", base class "B" defined the type as "List[int]")
7790+ main:6 : error: Incompatible types in assignment (expression has type "List[str]", base class "B" defined the type as "List[int]")
77857791
77867792[case testLiskovFineVariableCleanDefInMethodNested-only_when_nocache]
77877793from b import B
@@ -9109,27 +9115,27 @@ import a
91099115[file a.py]
91109116# mypy: no-warn-no-return
91119117
9112- from typing import List
9113- def foo() -> List:
9118+ from typing import List, Optional
9119+ def foo() -> Optional[ List] :
91149120 20
91159121
91169122[file a.py.2]
91179123# mypy: disallow-any-generics, no-warn-no-return
91189124
9119- from typing import List
9120- def foo() -> List:
9125+ from typing import List, Optional
9126+ def foo() -> Optional[ List] :
91219127 20
91229128
91239129[file a.py.3]
91249130# mypy: no-warn-no-return
91259131
9126- from typing import List
9127- def foo() -> List:
9132+ from typing import List, Optional
9133+ def foo() -> Optional[ List] :
91289134 20
91299135
91309136[file a.py.4]
9131- from typing import List
9132- def foo() -> List:
9137+ from typing import List, Optional
9138+ def foo() -> Optional[ List] :
91339139 20
91349140[out]
91359141==
@@ -9867,7 +9873,7 @@ x = 0 # Arbitrary change to trigger reprocessing
98679873[builtins fixtures/dict.pyi]
98689874[out]
98699875==
9870- a.py:5: note: Revealed type is "def (x: builtins.int) -> builtins.str"
9876+ a.py:5: note: Revealed type is "def (x: builtins.int) -> Union[ builtins.str, None] "
98719877
98729878[case testTypeVarTupleCached]
98739879import a
0 commit comments