Skip to content

Commit 6b8e02c

Browse files
committed
feat: extreme-self-casting
1 parent 95b8086 commit 6b8e02c

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
TODO:
3+
4+
make Fn[VnCallable] could be casted to a Callable with a Any value.
5+
you MUST NOT modify anything expect the `Fn.into_callable`'s annotation.
6+
"""
7+
8+
from typing import Callable, TypeVar, Generic, Any, assert_type
9+
10+
VnCallable = TypeVar("VnCallable", bound=Callable)
11+
12+
class Fn(Generic[VnCallable]):
13+
def __init__(self, f: VnCallable) -> None:
14+
self.f = f
15+
16+
def into_callable(self) -> None:
17+
...
18+
19+
20+
def should_pass():
21+
@Fn
22+
def example(a: int, b: str, c: float, *, d: bool = False) -> None:
23+
return
24+
25+
assert_type(example.f(1, "1", 1., d=False), None)
26+
27+
a: Any = 11111111
28+
29+
b = example.into_callable()(a, 1, "1", 1., d=False)
30+
31+
assert_type(b, None)
32+
33+
34+
def should_fail():
35+
@Fn
36+
def example(a: int, b: str, c: float, *, d: bool = False) -> None:
37+
...
38+
39+
example.into_callable()(1, "1", 1., d=False)

0 commit comments

Comments
 (0)