Skip to content

Commit 387d788

Browse files
committed
Update tests; some formatting
1 parent 08dba7d commit 387d788

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

mypy/types.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,7 @@ def function_type(func: mypy.nodes.FuncBase, fallback: Instance) -> FunctionLike
15251525
implicit=True,
15261526
)
15271527

1528+
15281529
def get_typ_args(tp: Type) -> List[Type]:
15291530
if not isinstance(tp, (Instance, UnionType, TupleType, CallableType)):
15301531
return []
@@ -1533,7 +1534,8 @@ def get_typ_args(tp: Type) -> List[Type]:
15331534
tp.arg_types + [tp.ret_type])
15341535
return typ_args
15351536

1536-
def set_typ_args(tp: Type, args: List[Type]) -> Type:
1537+
1538+
def set_typ_args(tp: Type, new_args: List[Type]) -> Type:
15371539
if isinstance(tp, Instance):
15381540
return Instance(tp.type, new_args, tp.line)
15391541
if isinstance(tp, TupleType):

test-data/unit/check-generics.test

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -592,17 +592,14 @@ class Node(Generic[T, S]):
592592
def __init__(self, x: T, y: S) -> None:
593593
...
594594

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

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

612+
X = T # E: Invalid type "__main__.T" for aliasing
613+
615614
[builtins fixtures/list.pyi]
616615

617616
[case testGenericTypeAliasesForAliases]
@@ -904,13 +903,13 @@ CA = Callable[[T], int]
904903
TA = Tuple[T, int]
905904
UA = Union[T, int]
906905

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

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

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

916915
[out]

0 commit comments

Comments
 (0)