Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ddfisher committed Mar 19, 2017
1 parent 49d340a commit c0350ca
Show file tree
Hide file tree
Showing 23 changed files with 103 additions and 100 deletions.
6 changes: 3 additions & 3 deletions mypy/test/testsolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ def test_multiple_variables(self) -> None:
def test_no_constraints_for_var(self) -> None:
self.assert_solve([self.fx.t.id],
[],
[self.fx.nonet])
[self.fx.uninhabited])
self.assert_solve([self.fx.t.id, self.fx.s.id],
[],
[self.fx.nonet, self.fx.nonet])
[self.fx.uninhabited, self.fx.uninhabited])
self.assert_solve([self.fx.t.id, self.fx.s.id],
[self.supc(self.fx.s, self.fx.a)],
[self.fx.nonet, (self.fx.a, self.fx.o)])
[self.fx.uninhabited, (self.fx.a, self.fx.o)])

def test_simple_constraints_with_dynamic_type(self) -> None:
self.assert_solve([self.fx.t.id],
Expand Down
4 changes: 2 additions & 2 deletions mypy/test/testsubtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def test_basic_callable_subtyping(self) -> None:
self.assert_strict_subtype(self.fx.callable(self.fx.d, self.fx.b),
self.fx.callable(self.fx.d, self.fx.a))

self.assert_unrelated(self.fx.callable(self.fx.a, self.fx.a),
self.fx.callable(self.fx.a, self.fx.nonet))
self.assert_strict_subtype(self.fx.callable(self.fx.a, self.fx.nonet),
self.fx.callable(self.fx.a, self.fx.a))

self.assert_unrelated(
self.fx.callable(self.fx.a, self.fx.a, self.fx.a),
Expand Down
3 changes: 2 additions & 1 deletion mypy/typefixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from mypy.types import (
Type, TypeVarType, AnyType, ErrorType, NoneTyp,
Instance, CallableType, TypeVarDef, TypeType,
Instance, CallableType, TypeVarDef, TypeType, UninhabitedType
)
from mypy.nodes import (
TypeInfo, ClassDef, Block, ARG_POS, ARG_OPT, ARG_STAR, SymbolTable,
Expand Down Expand Up @@ -43,6 +43,7 @@ def make_type_var(name: str, id: int, values: List[Type], upper_bound: Type,
self.anyt = AnyType()
self.err = ErrorType()
self.nonet = NoneTyp()
self.uninhabited = UninhabitedType()

# Abstract class TypeInfos

Expand Down
3 changes: 2 additions & 1 deletion mypy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,8 @@ def visit_callable_type(self, t: CallableType) -> str:

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

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

if t.variables:
s = '{} {}'.format(t.variables, s)
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-async-await.test
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class C:
def __aenter__(self) -> None: pass
async def __aexit__(self, x, y, z) -> None: pass
async def f() -> None:
async with C() as x: # E: "__aenter__" of "C" does not return a value
async with C() as x: # E: None has no attribute "__await__"
pass
[builtins fixtures/async_await.pyi]
[out]
Expand All @@ -304,7 +304,7 @@ class C:
async def __aenter__(self) -> int: pass
def __aexit__(self, x, y, z) -> None: pass
async def f() -> None:
async with C() as x: # E: "__aexit__" of "C" does not return a value
async with C() as x: # E: None has no attribute "__await__"
pass
[builtins fixtures/async_await.pyi]
[out]
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-bound.test
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class C(Generic[T]):
return self.t
c1 = None # type: C[None]
c1.get()
d = c1.get() # E: Function does not return a value
d = c1.get() # E: "get" of "C" does not return a value


[case testBoundAny]
Expand All @@ -82,7 +82,7 @@ def f(g: Callable[[], T]) -> T:
return g()
def h() -> None: pass
f(h)
a = f(h) # E: "h" does not return a value
a = f(h) # E: "f" does not return a value


[case testBoundInheritance]
Expand Down
10 changes: 3 additions & 7 deletions test-data/unit/check-classes.test
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,9 @@ class A:
def g(self) -> 'A': pass
class B(A):
def f(self) -> A: pass # Fail
def g(self) -> None: pass # Fail
def g(self) -> None: pass
[out]
main:6: error: Return type of "f" incompatible with supertype "A"
main:7: error: Return type of "g" incompatible with supertype "A"

[case testOverride__new__WithDifferentSignature]
class A:
Expand Down Expand Up @@ -727,12 +726,9 @@ import typing
class A:
def f(self) -> None:
def g() -> None:
a = None
b = None
"" + 1 # E: Unsupported operand types for + ("str" and "int")
"" + 1 # E: Unsupported operand types for + ("str" and "int")
[out]
main:5: error: Need type annotation for variable
main:6: error: Need type annotation for variable


-- Static methods
-- --------------
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-dynamic-typing.test
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ f11 = None # type: Callable[[], Any]
f2 = None # type: Callable[[], A]
f3 = None # type: Callable[[], None]

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

f1 = f2
f1 = f3
Expand Down
16 changes: 10 additions & 6 deletions test-data/unit/check-expressions.test
Original file line number Diff line number Diff line change
Expand Up @@ -921,8 +921,8 @@ a = None # type: A
f() + a # E: "f" does not return a value
a + f() # E: "f" does not return a value
f() == a # E: "f" does not return a value
a != f() # E: Unsupported left operand type for != ("A")
cast(A, f()) # E: "f" does not return a value
a != f() # E: "f" does not return a value
cast(A, f())
f().foo # E: "f" does not return a value

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

a, b = None, None # type: (A, bool)
a < f() # E: Unsupported left operand type for < ("A")
f() in a
a < f() # E: "f" does not return a value
f() <= a # E: "f" does not return a value
f() in a # E: Unsupported right operand type for in ("A")
a in f() # E: "f" does not return a value
-f() # E: "f" does not return a value
not f() # E: "f" does not return a value
Expand All @@ -947,6 +947,9 @@ class A:
def __add__(self, x: 'A') -> 'A':
pass
[builtins fixtures/bool.pyi]
[out]
main:3: error: "f" does not return a value
main:3: error: Unsupported right operand type for in ("A")


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

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


[case testYieldFromIteratorHasNoValue]
[case testYieldFromIteratorIsNone]
from typing import Iterator
def f() -> Iterator[int]:
yield 5
def g() -> Iterator[int]:
a = yield from f()
reveal_type(a) # E: Revealed type is 'builtins.None'
[out]
main:5: error: Function does not return a value

[case testYieldFromGeneratorHasValue]
from typing import Iterator, Generator
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-functions.test
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ from typing import Callable
f = None # type: Callable[[], None]
g = None # type: Callable[[], object]
f = g # E: Incompatible types in assignment (expression has type Callable[[], object], variable has type Callable[[], None])
g = f # E: Incompatible types in assignment (expression has type Callable[[], None], variable has type Callable[[], object])
g = f # OK

f = f
g = g
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-generic-subtyping.test
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ B(1)
C(1)
C('a') # E: Argument 1 to "C" has incompatible type "str"; expected "int"
D(A(1))
D(1) # E: Argument 1 to "D" has incompatible type "int"; expected A[None]
D(1) # E: Argument 1 to "D" has incompatible type "int"; expected A[<uninhabited>]


[case testInheritedConstructor2]
Expand Down
6 changes: 3 additions & 3 deletions test-data/unit/check-generics.test
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ def func(x: IntNode[T]) -> IntNode[T]:
return x
reveal_type(func) # E: Revealed type is 'def [T] (x: __main__.Node[builtins.int, T`-1]) -> __main__.Node[builtins.int, T`-1]'

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

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

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

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

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

Expand Down
25 changes: 19 additions & 6 deletions test-data/unit/check-inference-context.test
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ b = None # type: B

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

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

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

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

class A(Generic[T]): pass
class B: pass
Expand Down Expand Up @@ -334,7 +334,7 @@ aa = None # type: List[A]
ao = None # type: List[object]
a = None # type: A

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

aa = []
ao = []
Expand Down Expand Up @@ -385,7 +385,7 @@ class B(A): pass
import typing
def f() -> None:
a = [] # E: Need type annotation for variable
b = [None] # E: Need type annotation for variable
b = [None]
c = [B()]
c = [object()] # E: List item 0 has incompatible type "object"
c = [B()]
Expand Down Expand Up @@ -755,7 +755,7 @@ T = TypeVar('T')
def f(x: Union[List[T], str]) -> None: pass
f([1])
f('')
f(1) # E: Argument 1 to "f" has incompatible type "int"; expected "Union[List[None], str]"
f(1) # E: Argument 1 to "f" has incompatible type "int"; expected "Union[List[<uninhabited>], str]"
[builtins fixtures/isinstancelist.pyi]

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

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

def f(d: M[_KT, _VT], k: _KT) -> _VT:
return d.get(k, None) # E: "get" of "M" does not return a value

[case testGenericMethodCalledInGenericContext2]
from typing import TypeVar, Generic, Union

_KT = TypeVar('_KT')
_VT = TypeVar('_VT')
_T = TypeVar('_T')

class M(Generic[_KT, _VT]):
def get(self, k: _KT, default: _T) -> Union[_VT, _T]: ...

def f(d: M[_KT, _VT], k: _KT) -> Union[_VT, None]:
return d.get(k, None)
Loading

0 comments on commit c0350ca

Please sign in to comment.