-
Notifications
You must be signed in to change notification settings - Fork 30
/
solution2.py
39 lines (24 loc) · 949 Bytes
/
solution2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""
TODO:
Fn is a class decorator which takes a callable (`f`).
Fn has a `transform_callable` method, which transform `f` into a different callable,
with an additional Any parameter at the beginning, while preserving the remaining parts
of the function signature.
Note: you're only requried to add type annotations without implementing transform_callable.
"""
from typing import Callable, Concatenate, Any
class Fn[R, **P]():
def __init__(self, f: Callable[P, R]) -> None:
self.f = f
def transform_callable(self) -> Callable[Concatenate[Any, P], R]:
...
## End of your code ##
from typing import assert_type
@Fn
def example(a: int, b: str, c: float, *, d: bool = False) -> None:
return
assert_type(example.f(1, "1", 1.0, d=False), None)
a: Any = 11111111
b = example.transform_callable()(a, 1, "1", 1.0, d=False)
assert_type(b, None)
example.transform_callable()(1, "1", 1.0, d=False) # expect-type-error