Skip to content

Commit

Permalink
Update tests; some formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ilevkivskyi committed Nov 1, 2016
1 parent 64fc96e commit 8c64111
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
4 changes: 3 additions & 1 deletion mypy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1525,6 +1525,7 @@ def function_type(func: mypy.nodes.FuncBase, fallback: Instance) -> FunctionLike
implicit=True,
)


def get_typ_args(tp: Type) -> List[Type]:
if not isinstance(tp, (Instance, UnionType, TupleType, CallableType)):
return []
Expand All @@ -1533,7 +1534,8 @@ def get_typ_args(tp: Type) -> List[Type]:
tp.arg_types + [tp.ret_type])
return typ_args

def set_typ_args(tp: Type, args: List[Type]) -> Type:

def set_typ_args(tp: Type, new_args: List[Type]) -> Type:
if isinstance(tp, Instance):
return Instance(tp.type, new_args, tp.line)
if isinstance(tp, TupleType):
Expand Down
15 changes: 7 additions & 8 deletions test-data/unit/check-generics.test
Original file line number Diff line number Diff line change
Expand Up @@ -592,17 +592,14 @@ class Node(Generic[T, S]):
def __init__(self, x: T, y: S) -> None:
...

A = Node[T] # E: Type application has too few types (2 expected)
A = Node[T] # E: "Node" expects 2 type arguments, but 1 given
B = Node[T, T]
C = Node[T, T, T] # E: Type application has too many types (2 expected)
C = Node[T, T, T] # E: "Node" expects 2 type arguments, but 3 given
D = Node[T, S]
E = Node[Node[T, T], List[T]]

# Errors for F, G, H are not reported if those aliases left used
F = Node[List[T, T], S] # E: "list" expects 1 type argument, but 2 given
f = None # type: F
G = Callable[..., List[T, T]] # E: "list" expects 1 type argument, but 2 given
g = None # type: G[int]
H = Union[int, Tuple[T, Node[T]]] # E: "Node" expects 2 type arguments, but 1 given
h = None # type: H
h1 = None # type: H[int, str] # E: Bad number of arguments for type alias, expected: 1, given: 2
Expand All @@ -612,6 +609,8 @@ reveal_type(x) # E: Revealed type is '__main__.Node[builtins.int, builtins.str]'
y = None # type: E[int]
reveal_type(y) # E: Revealed type is '__main__.Node[__main__.Node[builtins.int, builtins.int], builtins.list[builtins.int]]'

X = T # E: Invalid type "__main__.T" for aliasing

[builtins fixtures/list.pyi]

[case testGenericTypeAliasesForAliases]
Expand Down Expand Up @@ -904,13 +903,13 @@ CA = Callable[[T], int]
TA = Tuple[T, int]
UA = Union[T, int]

cs = CA[str]() # E: Invalid type alias in runtime expression: def (builtins.str) -> builtins.int
cs = CA[str] + 1 # E: Unsupported left operand type for + ("Type alias to Callable")
reveal_type(cs) # E: Revealed type is 'Any'

ts = TA[str]() # E: Invalid type alias in runtime expression: Tuple[builtins.str, builtins.int]
ts = TA[str]() # E: "Type alias to Tuple" not callable
reveal_type(ts) # E: Revealed type is 'Any'

us = UA[str]() # E: Invalid type alias in runtime expression: Union[builtins.str, builtins.int]
us = UA[str].x # E: "Type alias to Union" has no attribute "x"
reveal_type(us) # E: Revealed type is 'Any'

[out]
Expand Down

0 comments on commit 8c64111

Please sign in to comment.