Skip to content

Commit 18ba589

Browse files
committed
Improve advanced-variadic-generics challenge
1 parent d113897 commit 18ba589

File tree

3 files changed

+10
-30
lines changed

3 files changed

+10
-30
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Check out [TypeVarTuple](https://docs.python.org/3/library/typing.html#typing.TypeVarTuple).

challenges/advanced-variadic-generics/solution.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
Define an `Array` type that supports element-wise addition of arrays with identical dimensions and types.
55
"""
66

7-
from typing import Generic, TypeVar, TypeVarTuple, assert_type
8-
9-
T = TypeVar("T")
10-
Ts = TypeVarTuple("Ts")
11-
12-
13-
class Array(Generic[*Ts]):
7+
# For Python < 3.12
8+
# Ts = TypeVarTuple("Ts")
9+
#
10+
# class Array(Generic[*Ts]):
11+
# def __add__(self, other: "Array[*Ts]") -> "Array[*Ts]":
12+
# ...
13+
14+
# For Python >= 3.12
15+
class Array[*Ts]:
1416
def __add__(self, other: "Array[*Ts]") -> "Array[*Ts]":
1517
...
1618

challenges/advanced-variadic-generics/solution2.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)