Skip to content

Commit c0350ca

Browse files
committed
Fix tests
1 parent 49d340a commit c0350ca

23 files changed

+103
-100
lines changed

mypy/test/testsolve.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ def test_multiple_variables(self) -> None:
6464
def test_no_constraints_for_var(self) -> None:
6565
self.assert_solve([self.fx.t.id],
6666
[],
67-
[self.fx.nonet])
67+
[self.fx.uninhabited])
6868
self.assert_solve([self.fx.t.id, self.fx.s.id],
6969
[],
70-
[self.fx.nonet, self.fx.nonet])
70+
[self.fx.uninhabited, self.fx.uninhabited])
7171
self.assert_solve([self.fx.t.id, self.fx.s.id],
7272
[self.supc(self.fx.s, self.fx.a)],
73-
[self.fx.nonet, (self.fx.a, self.fx.o)])
73+
[self.fx.uninhabited, (self.fx.a, self.fx.o)])
7474

7575
def test_simple_constraints_with_dynamic_type(self) -> None:
7676
self.assert_solve([self.fx.t.id],

mypy/test/testsubtypes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ def test_basic_callable_subtyping(self) -> None:
8484
self.assert_strict_subtype(self.fx.callable(self.fx.d, self.fx.b),
8585
self.fx.callable(self.fx.d, self.fx.a))
8686

87-
self.assert_unrelated(self.fx.callable(self.fx.a, self.fx.a),
88-
self.fx.callable(self.fx.a, self.fx.nonet))
87+
self.assert_strict_subtype(self.fx.callable(self.fx.a, self.fx.nonet),
88+
self.fx.callable(self.fx.a, self.fx.a))
8989

9090
self.assert_unrelated(
9191
self.fx.callable(self.fx.a, self.fx.a, self.fx.a),

mypy/typefixture.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from mypy.types import (
99
Type, TypeVarType, AnyType, ErrorType, NoneTyp,
10-
Instance, CallableType, TypeVarDef, TypeType,
10+
Instance, CallableType, TypeVarDef, TypeType, UninhabitedType
1111
)
1212
from mypy.nodes import (
1313
TypeInfo, ClassDef, Block, ARG_POS, ARG_OPT, ARG_STAR, SymbolTable,
@@ -43,6 +43,7 @@ def make_type_var(name: str, id: int, values: List[Type], upper_bound: Type,
4343
self.anyt = AnyType()
4444
self.err = ErrorType()
4545
self.nonet = NoneTyp()
46+
self.uninhabited = UninhabitedType()
4647

4748
# Abstract class TypeInfos
4849

mypy/types.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,8 @@ def visit_callable_type(self, t: CallableType) -> str:
14121412

14131413
s = '({})'.format(s)
14141414

1415-
s += ' -> {}'.format(t.ret_type)
1415+
if not isinstance(t.ret_type, NoneTyp):
1416+
s += ' -> {}'.format(t.ret_type)
14161417

14171418
if t.variables:
14181419
s = '{} {}'.format(t.variables, s)

test-data/unit/check-async-await.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ class C:
282282
def __aenter__(self) -> None: pass
283283
async def __aexit__(self, x, y, z) -> None: pass
284284
async def f() -> None:
285-
async with C() as x: # E: "__aenter__" of "C" does not return a value
285+
async with C() as x: # E: None has no attribute "__await__"
286286
pass
287287
[builtins fixtures/async_await.pyi]
288288
[out]
@@ -304,7 +304,7 @@ class C:
304304
async def __aenter__(self) -> int: pass
305305
def __aexit__(self, x, y, z) -> None: pass
306306
async def f() -> None:
307-
async with C() as x: # E: "__aexit__" of "C" does not return a value
307+
async with C() as x: # E: None has no attribute "__await__"
308308
pass
309309
[builtins fixtures/async_await.pyi]
310310
[out]

test-data/unit/check-bound.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class C(Generic[T]):
5656
return self.t
5757
c1 = None # type: C[None]
5858
c1.get()
59-
d = c1.get() # E: Function does not return a value
59+
d = c1.get() # E: "get" of "C" does not return a value
6060

6161

6262
[case testBoundAny]
@@ -82,7 +82,7 @@ def f(g: Callable[[], T]) -> T:
8282
return g()
8383
def h() -> None: pass
8484
f(h)
85-
a = f(h) # E: "h" does not return a value
85+
a = f(h) # E: "f" does not return a value
8686

8787

8888
[case testBoundInheritance]

test-data/unit/check-classes.test

+3-7
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,9 @@ class A:
281281
def g(self) -> 'A': pass
282282
class B(A):
283283
def f(self) -> A: pass # Fail
284-
def g(self) -> None: pass # Fail
284+
def g(self) -> None: pass
285285
[out]
286286
main:6: error: Return type of "f" incompatible with supertype "A"
287-
main:7: error: Return type of "g" incompatible with supertype "A"
288287

289288
[case testOverride__new__WithDifferentSignature]
290289
class A:
@@ -727,12 +726,9 @@ import typing
727726
class A:
728727
def f(self) -> None:
729728
def g() -> None:
730-
a = None
731-
b = None
729+
"" + 1 # E: Unsupported operand types for + ("str" and "int")
730+
"" + 1 # E: Unsupported operand types for + ("str" and "int")
732731
[out]
733-
main:5: error: Need type annotation for variable
734-
main:6: error: Need type annotation for variable
735-
736732

737733
-- Static methods
738734
-- --------------

test-data/unit/check-dynamic-typing.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ f11 = None # type: Callable[[], Any]
537537
f2 = None # type: Callable[[], A]
538538
f3 = None # type: Callable[[], None]
539539

540-
f2 = f3 # E: Incompatible types in assignment (expression has type Callable[[], None], variable has type Callable[[], A])
540+
f2 = f3
541541

542542
f1 = f2
543543
f1 = f3

test-data/unit/check-expressions.test

+10-6
Original file line numberDiff line numberDiff line change
@@ -921,8 +921,8 @@ a = None # type: A
921921
f() + a # E: "f" does not return a value
922922
a + f() # E: "f" does not return a value
923923
f() == a # E: "f" does not return a value
924-
a != f() # E: Unsupported left operand type for != ("A")
925-
cast(A, f()) # E: "f" does not return a value
924+
a != f() # E: "f" does not return a value
925+
cast(A, f())
926926
f().foo # E: "f" does not return a value
927927

928928
def f() -> None: pass
@@ -933,9 +933,9 @@ class A:
933933
[case testNoneReturnTypeWithExpressions2]
934934

935935
a, b = None, None # type: (A, bool)
936-
a < f() # E: Unsupported left operand type for < ("A")
936+
f() in a
937+
a < f() # E: "f" does not return a value
937938
f() <= a # E: "f" does not return a value
938-
f() in a # E: Unsupported right operand type for in ("A")
939939
a in f() # E: "f" does not return a value
940940
-f() # E: "f" does not return a value
941941
not f() # E: "f" does not return a value
@@ -947,6 +947,9 @@ class A:
947947
def __add__(self, x: 'A') -> 'A':
948948
pass
949949
[builtins fixtures/bool.pyi]
950+
[out]
951+
main:3: error: "f" does not return a value
952+
main:3: error: Unsupported right operand type for in ("A")
950953

951954

952955
-- Slicing
@@ -1458,6 +1461,7 @@ def f(x: int) -> None:
14581461
[out]
14591462
main:1: error: The return type of a generator function should be "Generator" or one of its supertypes
14601463
main:2: error: Argument 1 to "f" has incompatible type "str"; expected "int"
1464+
main:2: error: "f" does not return a value
14611465

14621466
[case testYieldExpressionWithNone]
14631467
from typing import Iterator
@@ -1471,14 +1475,14 @@ def f(x: int) -> Iterator[None]:
14711475
-- ----------------
14721476

14731477

1474-
[case testYieldFromIteratorHasNoValue]
1478+
[case testYieldFromIteratorIsNone]
14751479
from typing import Iterator
14761480
def f() -> Iterator[int]:
14771481
yield 5
14781482
def g() -> Iterator[int]:
14791483
a = yield from f()
1484+
reveal_type(a) # E: Revealed type is 'builtins.None'
14801485
[out]
1481-
main:5: error: Function does not return a value
14821486

14831487
[case testYieldFromGeneratorHasValue]
14841488
from typing import Iterator, Generator

test-data/unit/check-functions.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ from typing import Callable
208208
f = None # type: Callable[[], None]
209209
g = None # type: Callable[[], object]
210210
f = g # E: Incompatible types in assignment (expression has type Callable[[], object], variable has type Callable[[], None])
211-
g = f # E: Incompatible types in assignment (expression has type Callable[[], None], variable has type Callable[[], object])
211+
g = f # OK
212212

213213
f = f
214214
g = g

test-data/unit/check-generic-subtyping.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ B(1)
394394
C(1)
395395
C('a') # E: Argument 1 to "C" has incompatible type "str"; expected "int"
396396
D(A(1))
397-
D(1) # E: Argument 1 to "D" has incompatible type "int"; expected A[None]
397+
D(1) # E: Argument 1 to "D" has incompatible type "int"; expected A[<uninhabited>]
398398

399399

400400
[case testInheritedConstructor2]

test-data/unit/check-generics.test

+3-3
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ def func(x: IntNode[T]) -> IntNode[T]:
565565
return x
566566
reveal_type(func) # E: Revealed type is 'def [T] (x: __main__.Node[builtins.int, T`-1]) -> __main__.Node[builtins.int, T`-1]'
567567

568-
func(1) # E: Argument 1 to "func" has incompatible type "int"; expected Node[int, None]
568+
func(1) # E: Argument 1 to "func" has incompatible type "int"; expected Node[int, <uninhabited>]
569569
func(Node('x', 1)) # E: Argument 1 to "Node" has incompatible type "str"; expected "int"
570570
reveal_type(func(Node(1, 'x'))) # E: Revealed type is '__main__.Node[builtins.int, builtins.str*]'
571571

@@ -800,7 +800,7 @@ reveal_type(x) # E: Revealed type is 'builtins.int'
800800
def f2(x: IntTP[T]) -> IntTP[T]:
801801
return x
802802

803-
f2((1, 2, 3)) # E: Argument 1 to "f2" has incompatible type "Tuple[int, int, int]"; expected "Tuple[int, None]"
803+
f2((1, 2, 3)) # E: Argument 1 to "f2" has incompatible type "Tuple[int, int, int]"; expected "Tuple[int, <uninhabited>]"
804804
reveal_type(f2((1, 'x'))) # E: Revealed type is 'Tuple[builtins.int, builtins.str*]'
805805

806806
[builtins fixtures/for.pyi]
@@ -869,7 +869,7 @@ n.y = 'x' # E: Incompatible types in assignment (expression has type "str", vari
869869
def f(x: Node[T, T]) -> TupledNode[T]:
870870
return Node(x.x, (x.x, x.x))
871871

872-
f(1) # E: Argument 1 to "f" has incompatible type "int"; expected Node[None, None]
872+
f(1) # E: Argument 1 to "f" has incompatible type "int"; expected Node[<uninhabited>, <uninhabited>]
873873
f(Node(1, 'x')) # E: Cannot infer type argument 1 of "f"
874874
reveal_type(Node('x', 'x')) # E: Revealed type is 'a.Node[builtins.str*, builtins.str*]'
875875

test-data/unit/check-inference-context.test

+19-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ b = None # type: B
1313

1414
ao = f()
1515
ab = f()
16-
b = f() # E: Incompatible types in assignment (expression has type A[None], variable has type "B")
16+
b = f() # E: Incompatible types in assignment (expression has type A[<uninhabited>], variable has type "B")
1717

1818
def f() -> 'A[T]': pass
1919

@@ -29,7 +29,7 @@ b = None # type: B
2929

3030
ao = A()
3131
ab = A()
32-
b = A() # E: Incompatible types in assignment (expression has type A[None], variable has type "B")
32+
b = A() # E: Incompatible types in assignment (expression has type A[<uninhabited>], variable has type "B")
3333

3434
class A(Generic[T]): pass
3535
class B: pass
@@ -334,7 +334,7 @@ aa = None # type: List[A]
334334
ao = None # type: List[object]
335335
a = None # type: A
336336

337-
a = [] # E: Incompatible types in assignment (expression has type List[None], variable has type "A")
337+
a = [] # E: Incompatible types in assignment (expression has type List[<uninhabited>], variable has type "A")
338338

339339
aa = []
340340
ao = []
@@ -385,7 +385,7 @@ class B(A): pass
385385
import typing
386386
def f() -> None:
387387
a = [] # E: Need type annotation for variable
388-
b = [None] # E: Need type annotation for variable
388+
b = [None]
389389
c = [B()]
390390
c = [object()] # E: List item 0 has incompatible type "object"
391391
c = [B()]
@@ -755,7 +755,7 @@ T = TypeVar('T')
755755
def f(x: Union[List[T], str]) -> None: pass
756756
f([1])
757757
f('')
758-
f(1) # E: Argument 1 to "f" has incompatible type "int"; expected "Union[List[None], str]"
758+
f(1) # E: Argument 1 to "f" has incompatible type "int"; expected "Union[List[<uninhabited>], str]"
759759
[builtins fixtures/isinstancelist.pyi]
760760

761761
[case testIgnoringInferenceContext]
@@ -824,7 +824,7 @@ from typing import TypeVar, Callable, Generic
824824
T = TypeVar('T')
825825
class A(Generic[T]):
826826
pass
827-
reveal_type(A()) # E: Revealed type is '__main__.A[builtins.None]'
827+
reveal_type(A()) # E: Revealed type is '__main__.A[<uninhabited>]'
828828
b = reveal_type(A()) # type: A[int] # E: Revealed type is '__main__.A[builtins.int]'
829829

830830
[case testUnionWithGenericTypeItemContext]
@@ -877,4 +877,17 @@ class M(Generic[_KT, _VT]):
877877
def get(self, k: _KT, default: _T) -> _T: ...
878878

879879
def f(d: M[_KT, _VT], k: _KT) -> _VT:
880+
return d.get(k, None) # E: "get" of "M" does not return a value
881+
882+
[case testGenericMethodCalledInGenericContext2]
883+
from typing import TypeVar, Generic, Union
884+
885+
_KT = TypeVar('_KT')
886+
_VT = TypeVar('_VT')
887+
_T = TypeVar('_T')
888+
889+
class M(Generic[_KT, _VT]):
890+
def get(self, k: _KT, default: _T) -> Union[_VT, _T]: ...
891+
892+
def f(d: M[_KT, _VT], k: _KT) -> Union[_VT, None]:
880893
return d.get(k, None)

0 commit comments

Comments
 (0)