@@ -191,7 +191,7 @@ main:3: error: "A" has no attribute "x"
191
191
[case testVariableTypeBecomesInvalid]
192
192
import m
193
193
def f() -> None:
194
- a = None # type : m.A
194
+ a: m.A
195
195
[file m.py]
196
196
class A: pass
197
197
[file m.py.2]
@@ -1724,15 +1724,15 @@ f = 1
1724
1724
main:1: error: Module "a" has no attribute "f"
1725
1725
1726
1726
[case testDecoratedMethodRefresh]
1727
- from typing import Iterator, Callable, List
1727
+ from typing import Iterator, Callable, List, Optional
1728
1728
from a import f
1729
1729
import a
1730
1730
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
1732
1732
1733
1733
class A:
1734
1734
@dec
1735
- def f(self) -> Iterator[int]:
1735
+ def f(self) -> Optional[ Iterator[int] ]:
1736
1736
self.x = a.g() # type: int
1737
1737
return None
1738
1738
[builtins fixtures/list.pyi]
@@ -4626,6 +4626,7 @@ class User:
4626
4626
==
4627
4627
4628
4628
[case testNoStrictOptionalModule]
4629
+ # flags: --no-strict-optional
4629
4630
import a
4630
4631
a.y = a.x
4631
4632
[file a.py]
@@ -4643,9 +4644,10 @@ y: int
4643
4644
[out]
4644
4645
==
4645
4646
==
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")
4647
4648
4648
4649
[case testNoStrictOptionalFunction]
4650
+ # flags: --no-strict-optional
4649
4651
import a
4650
4652
from typing import Optional
4651
4653
def f() -> None:
@@ -4666,9 +4668,10 @@ def g(x: str) -> None:
4666
4668
[out]
4667
4669
==
4668
4670
==
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"
4670
4672
4671
4673
[case testNoStrictOptionalMethod]
4674
+ # flags: --no-strict-optional
4672
4675
import a
4673
4676
from typing import Optional
4674
4677
class C:
@@ -4693,7 +4696,7 @@ class B:
4693
4696
[out]
4694
4697
==
4695
4698
==
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"
4697
4700
4698
4701
[case testStrictOptionalModule]
4699
4702
# flags: --strict-optional
@@ -5276,10 +5279,11 @@ class I(metaclass=ABCMeta):
5276
5279
@abstractmethod
5277
5280
def f(self) -> None: pass
5278
5281
[file b.py]
5282
+ from typing import Optional
5279
5283
from z import I
5280
5284
class Foo(I):
5281
5285
pass
5282
- def x() -> Foo: return None
5286
+ def x() -> Optional[ Foo] : return None
5283
5287
[file z.py.2]
5284
5288
from abc import abstractmethod, ABCMeta
5285
5289
class I(metaclass=ABCMeta):
@@ -5301,10 +5305,11 @@ class I(metaclass=ABCMeta):
5301
5305
@abstractmethod
5302
5306
def f(self) -> None: pass
5303
5307
[file b.py]
5308
+ from typing import Optional
5304
5309
from a import I
5305
5310
class Foo(I):
5306
5311
pass
5307
- def x() -> Foo: return None
5312
+ def x() -> Optional[ Foo] : return None
5308
5313
[file a.py.2]
5309
5314
from abc import abstractmethod, ABCMeta
5310
5315
class I(metaclass=ABCMeta):
@@ -7769,7 +7774,8 @@ from typing import List
7769
7774
import b
7770
7775
class A(b.B):
7771
7776
def meth(self) -> None:
7772
- self.x, *self.y = None, None # type: str, List[str]
7777
+ self.x: str
7778
+ self.y: List[str]
7773
7779
[file b.py]
7774
7780
from typing import List
7775
7781
class B:
@@ -7781,7 +7787,7 @@ class B:
7781
7787
[builtins fixtures/list.pyi]
7782
7788
[out]
7783
7789
==
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]")
7785
7791
7786
7792
[case testLiskovFineVariableCleanDefInMethodNested-only_when_nocache]
7787
7793
from b import B
@@ -9109,27 +9115,27 @@ import a
9109
9115
[file a.py]
9110
9116
# mypy: no-warn-no-return
9111
9117
9112
- from typing import List
9113
- def foo() -> List:
9118
+ from typing import List, Optional
9119
+ def foo() -> Optional[ List] :
9114
9120
20
9115
9121
9116
9122
[file a.py.2]
9117
9123
# mypy: disallow-any-generics, no-warn-no-return
9118
9124
9119
- from typing import List
9120
- def foo() -> List:
9125
+ from typing import List, Optional
9126
+ def foo() -> Optional[ List] :
9121
9127
20
9122
9128
9123
9129
[file a.py.3]
9124
9130
# mypy: no-warn-no-return
9125
9131
9126
- from typing import List
9127
- def foo() -> List:
9132
+ from typing import List, Optional
9133
+ def foo() -> Optional[ List] :
9128
9134
20
9129
9135
9130
9136
[file a.py.4]
9131
- from typing import List
9132
- def foo() -> List:
9137
+ from typing import List, Optional
9138
+ def foo() -> Optional[ List] :
9133
9139
20
9134
9140
[out]
9135
9141
==
@@ -9867,7 +9873,7 @@ x = 0 # Arbitrary change to trigger reprocessing
9867
9873
[builtins fixtures/dict.pyi]
9868
9874
[out]
9869
9875
==
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] "
9871
9877
9872
9878
[case testTypeVarTupleCached]
9873
9879
import a
0 commit comments