Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions challenges/advanced-variadic-generics/question.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
TODO:

Define an `Array` type that supports element-wise addition of arrays with identical dimensions and types.
"""


class Array:
def __add__(self, other):
...


## End of your code ##
from typing import assert_type

a: Array[float, int] = Array()
b: Array[float, int] = Array()
assert_type(a + b, Array[float, int])

c: Array[float, int, str] = Array()
assert_type(a + c, Array[float, int, str]) # expect-type-error
26 changes: 26 additions & 0 deletions challenges/advanced-variadic-generics/solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
TODO:

Define an `Array` type that supports element-wise addition of arrays with identical dimensions and types.
"""

from typing import Generic, TypeVar, TypeVarTuple, assert_type

T = TypeVar("T")
Ts = TypeVarTuple("Ts")


class Array(Generic[*Ts]):
def __add__(self, other: "Array[*Ts]") -> "Array[*Ts]":
...


## End of your code ##
from typing import assert_type

a: Array[float, int] = Array()
b: Array[float, int] = Array()
assert_type(a + b, Array[float, int])

c: Array[float, int, str] = Array()
assert_type(a + c, Array[float, int, str]) # expect-type-error
23 changes: 23 additions & 0 deletions challenges/advanced-variadic-generics/solution2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
TODO:

Define an `Array` type that supports element-wise addition of arrays with identical dimensions and types.
"""

from typing import assert_type


class Array[*Ts]:
def __add__(self, other: "Array[*Ts]") -> "Array[*Ts]":
...


## End of your code ##
from typing import assert_type

a: Array[float, int] = Array()
b: Array[float, int] = Array()
assert_type(a + b, Array[float, int])

c: Array[float, int, str] = Array()
assert_type(a + c, Array[float, int, str]) # expect-type-error