-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_call.py
More file actions
74 lines (53 loc) · 1.49 KB
/
test_call.py
File metadata and controls
74 lines (53 loc) · 1.49 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import textwrap
from typing import Unpack
from typemap.type_eval import eval_call
from typemap_extensions import (
Attrs,
BaseTypedDict,
NewProtocol,
Member,
Iter,
)
from . import format_helper
def func[*T, K: BaseTypedDict](
*args: Unpack[T],
**kwargs: Unpack[K],
) -> NewProtocol[*[Member[c.name, int] for c in Iter[Attrs[K]]]]:
raise NotImplementedError
def test_call_1():
ret = eval_call(func, a=1, b=2, c="aaa")
fmt = format_helper.format_class(ret)
assert fmt == textwrap.dedent("""\
class func[...]:
a: int
b: int
c: int
""")
def func_trivial[*T, K: BaseTypedDict](
*args: Unpack[T],
**kwargs: Unpack[K],
) -> K:
return kwargs
def test_call_2():
ret = eval_call(func_trivial, a=1, b=2, c="aaa")
fmt = format_helper.format_class(ret)
assert fmt == textwrap.dedent("""\
class **kwargs:
a: typing.Literal[1]
b: typing.Literal[2]
c: typing.Literal['aaa']
""")
class Wrapped[T]: # noqa: B903
value: T
def __init__(self, value: T):
self.value = value
def wrapped[T](value: T) -> Wrapped[T]:
return Wrapped[T](value)
def test_call_3():
ret = eval_call(wrapped, 1)
fmt = format_helper.format_class(ret)
assert fmt == textwrap.dedent("""\
class Wrapped[typing.Literal[1]]:
value: typing.Literal[1]
def __init__(self: Self, value: Literal[1]) -> None: ...
""")