Skip to content

Commit

Permalink
Expand TypeVarTuple default (PEP 696)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p committed Feb 1, 2024
1 parent 9f51057 commit 7e08baf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 2 additions & 0 deletions mypy/expandtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ def visit_unpack_type(self, t: UnpackType) -> Type:
def expand_unpack(self, t: UnpackType) -> list[Type]:
assert isinstance(t.type, TypeVarTupleType)
repl = get_proper_type(self.variables.get(t.type.id, t.type))
if isinstance(repl, UnpackType):
repl = repl.type
if isinstance(repl, TupleType):
return repl.items
elif (
Expand Down
12 changes: 6 additions & 6 deletions test-data/unit/check-typevar-defaults.test
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ def func_c1(
# reveal_type(a) # Revealed type is "__main__.ClassC1[builtins.int, builtins.str]" # TODO
reveal_type(b) # N: Revealed type is "__main__.ClassC1[builtins.float]"

# k = ClassC1() # TODO
# reveal_type(k) # Revealed type is "__main__.ClassC1[builtins.int, builtins.str]" # TODO
k = ClassC1()
reveal_type(k) # N: Revealed type is "__main__.ClassC1[builtins.int, builtins.str]"
l = ClassC1[float]()
reveal_type(l) # N: Revealed type is "__main__.ClassC1[builtins.float]"

Expand All @@ -290,8 +290,8 @@ def func_c2(
# reveal_type(b) # Revealed type is "__main__.ClassC2[builtins.int, Unpack[builtins.tuple[builtins.float, ...]]]" # TODO
reveal_type(c) # N: Revealed type is "__main__.ClassC2[builtins.int]"

# k = ClassC2() # TODO
# reveal_type(k) # Revealed type is "__main__.ClassC2[builtins.str, Unpack[builtins.tuple[builtins.float, ...]]]" # TODO
k = ClassC2()
reveal_type(k) # N: Revealed type is "__main__.ClassC2[builtins.str, Unpack[builtins.tuple[builtins.float, ...]]]"
l = ClassC2[int]()
# reveal_type(l) # Revealed type is "__main__.ClassC2[builtins.int, Unpack[builtins.tuple[builtins.float, ...]]]" # TODO
m = ClassC2[int, Unpack[Tuple[()]]]()
Expand All @@ -308,8 +308,8 @@ def func_c3(
reveal_type(b) # N: Revealed type is "__main__.ClassC3[builtins.int]"
reveal_type(c) # N: Revealed type is "__main__.ClassC3[builtins.int, builtins.float]"

# k = ClassC3() # TODO
# reveal_type(k) # Revealed type is "__main__.ClassC3[builtins.str]" # TODO
k = ClassC3()
reveal_type(k) # N: Revealed type is "__main__.ClassC3[builtins.str]"
l = ClassC3[int]()
reveal_type(l) # N: Revealed type is "__main__.ClassC3[builtins.int]"
m = ClassC3[int, Unpack[Tuple[float]]]()
Expand Down

0 comments on commit 7e08baf

Please sign in to comment.