Skip to content

Commit d113897

Browse files
committed
Improve extreme-self-casting challenge
1 parent 3126219 commit d113897

File tree

3 files changed

+18
-47
lines changed

3 files changed

+18
-47
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Checkout [ParamSpec](https://docs.python.org/3/library/typing.html#typing.ParamSpec) and [Concatenate](https://docs.python.org/3/library/typing.html#typing.Concatenate).

challenges/extreme-self-casting/solution.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,25 @@
1212

1313
from typing import Callable, Concatenate, Generic, ParamSpec, TypeVar
1414

15-
16-
R = TypeVar("R")
17-
P = ParamSpec("P")
18-
19-
20-
class Fn(Generic[R, P]):
21-
def __init__(self, f: Callable[P, R]):
15+
# # For Python < 3.12
16+
# R = TypeVar("R")
17+
# P = ParamSpec("P")
18+
#
19+
#
20+
# class Fn(Generic[R, P]):
21+
# def __init__(self, f: Callable[P, R]):
22+
# self.f = f
23+
#
24+
# def transform_callable(self) -> Callable[Concatenate[object, P], R]:
25+
# ...
26+
27+
28+
# For Python >= 3.12
29+
class Fn[R, **P]:
30+
def __init__(self, f: Callable[P, R]) -> None:
2231
self.f = f
2332

24-
def transform_callable(self) -> Callable[Concatenate[object, P], R]:
33+
def transform_callable(self) -> Callable[Concatenate[Any, P], R]:
2534
...
2635

2736

challenges/extreme-self-casting/solution2.py

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

0 commit comments

Comments
 (0)