Skip to content

Commit 8f113e3

Browse files
committed
feat: advance-my-method
1 parent 6a003a2 commit 8f113e3

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""
2+
TODO:
3+
4+
a method-like descriptor, implements the `__get__` only.
5+
"""
6+
from typing import ParamSpec, TypeVar, Concatenate, Callable, Generic
7+
8+
P = ParamSpec("P")
9+
T = TypeVar("T")
10+
R = TypeVar("R")
11+
12+
class MyMethod(Generic[T, P, R]):
13+
def __init__(self, func: Callable[Concatenate[T, P], R]) -> None:
14+
self.func = func
15+
16+
def __get__(self, instance, owner) -> None:
17+
return
18+
19+
20+
21+
def should_pass():
22+
class Foo:
23+
@MyMethod
24+
def do_something(self, value: int) -> None:
25+
...
26+
27+
foo = Foo()
28+
29+
Foo.do_something(foo, 1111)
30+
foo.do_something(1111)
31+
32+
33+
def should_fail():
34+
class Foo:
35+
@MyMethod
36+
def do_something(self, value: int) -> None:
37+
...
38+
39+
foo = Foo()
40+
41+
Foo.do_something(1111)
42+
foo.do_something(11111, foo)
43+
foo.do_something(foo, 11111)

0 commit comments

Comments
 (0)