Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/test_dataclass_like.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Field[T: FieldArgs](typing.InitField[T]):
type InitFnType[T] = typing.Member[
Literal["__init__"],
Callable[
[
typing.Params[
typing.Param[Literal["self"], Self],
*[
typing.Param[
Expand Down
51 changes: 38 additions & 13 deletions tests/test_eval_call_with_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Iter,
Members,
Param,
Params,
)


Expand All @@ -19,36 +20,46 @@ def test_eval_call_with_types_callable_01():


def test_eval_call_with_types_callable_02():
res = eval_call_with_types(Callable[[Param[Literal["x"], int]], int], int)
res = eval_call_with_types(
Callable[Params[Param[Literal["x"], int]], int], int
)
assert res is int


def test_eval_call_with_types_callable_03():
res = eval_call_with_types(
Callable[[Param[Literal["x"], int, Literal["keyword"]]], int], x=int
Callable[Params[Param[Literal["x"], int, Literal["keyword"]]], int],
x=int,
)
assert res is int


def test_eval_call_with_types_callable_04():
class C: ...

res = eval_call_with_types(Callable[[Param[Literal["self"], Self]], int], C)
res = eval_call_with_types(
Callable[Params[Param[Literal["self"], Self]], int], C
)
assert res is int


def test_eval_call_with_types_callable_05():
class C: ...

res = eval_call_with_types(Callable[[Param[Literal["self"], Self]], C], C)
res = eval_call_with_types(
Callable[Params[Param[Literal["self"], Self]], C], C
)
assert res is C


def test_eval_call_with_types_callable_06():
class C: ...

res = eval_call_with_types(
Callable[[Param[Literal["self"], Self], Param[Literal["x"], int]], int],
Callable[
Params[Param[Literal["self"], Self], Param[Literal["x"], int]],
int,
],
C,
int,
)
Expand All @@ -60,7 +71,7 @@ class C: ...

res = eval_call_with_types(
Callable[
[
Params[
Param[Literal["self"], Self],
Param[Literal["x"], int, Literal["keyword"]],
],
Expand All @@ -74,13 +85,15 @@ class C: ...

def test_eval_call_with_types_callable_08():
T = TypeVar("T")
res = eval_call_with_types(Callable[[Param[Literal["x"], T]], str], int)
res = eval_call_with_types(
Callable[Params[Param[Literal["x"], T]], str], int
)
assert res is str


def test_eval_call_with_types_callable_09():
T = TypeVar("T")
res = eval_call_with_types(Callable[[Param[Literal["x"], T]], T], int)
res = eval_call_with_types(Callable[Params[Param[Literal["x"], T]], T], int)
assert res is int


Expand All @@ -89,7 +102,9 @@ def test_eval_call_with_types_callable_10():

class C(Generic[T]): ...

res = eval_call_with_types(Callable[[Param[Literal["x"], C[T]]], T], C[int])
res = eval_call_with_types(
Callable[Params[Param[Literal["x"], C[T]]], T], C[int]
)
assert res is int


Expand All @@ -102,9 +117,13 @@ class D(C[int]): ...

class E(D): ...

res = eval_call_with_types(Callable[[Param[Literal["x"], C[T]]], T], D)
res = eval_call_with_types(
Callable[Params[Param[Literal["x"], C[T]]], T], D
)
assert res is int
res = eval_call_with_types(Callable[[Param[Literal["x"], C[T]]], T], E)
res = eval_call_with_types(
Callable[Params[Param[Literal["x"], C[T]]], T], E
)
assert res is int


Expand Down Expand Up @@ -206,7 +225,10 @@ def test_eval_call_with_types_bind_error_01():
ValueError, match="Type variable T is already bound to int, but got str"
):
eval_call_with_types(
Callable[[Param[Literal["x"], T], Param[Literal["y"], T]], T],
Callable[
Params[Param[Literal["x"], T], Param[Literal["y"], T]],
T,
],
int,
str,
)
Expand All @@ -230,7 +252,10 @@ class C(Generic[T]): ...
ValueError, match="Type variable T is already bound to int, but got str"
):
eval_call_with_types(
Callable[[Param[Literal["x"], C[T]], Param[Literal["y"], C[T]]], T],
Callable[
Params[Param[Literal["x"], C[T]], Param[Literal["y"], C[T]]],
T,
],
C[int],
C[str],
)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_fastapilike_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
Member,
Members,
Param,
Params,
)

from . import format_helper
Expand Down Expand Up @@ -47,7 +48,7 @@ class _Default:
type InitFnType[T] = Member[
Literal["__init__"],
Callable[
[
Params[
Param[Literal["self"], Self],
*[
Param[
Expand Down
2 changes: 1 addition & 1 deletion tests/test_fastapilike_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class Field[T: FieldArgs](typing.InitField[T]):
type InitFnType[T] = typing.Member[
Literal["__init__"],
Callable[
[
typing.Params[
typing.Param[Literal["self"], Self],
*[
typing.Param[
Expand Down
16 changes: 9 additions & 7 deletions tests/test_schemalike.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Member,
NamedParam,
Param,
Params,
Concat,
)

Expand Down Expand Up @@ -46,7 +47,7 @@ class Property:
Member[
Concat[Literal["get_"], p.name],
Callable[
[
Params[
Param[Literal["self"], Schemaify[T]],
NamedParam[Literal["schema"], Schema, Literal["keyword"]],
],
Expand All @@ -63,16 +64,17 @@ def test_schema_like_1():
tgt = eval_typing(Schemaify[Property])
fmt = format_helper.format_class(tgt)

assert fmt == textwrap.dedent("""\
getter_params = "self: Self, *, schema: tests.test_schemalike.Schema"
assert fmt == textwrap.dedent(f"""\
class Schemaify[tests.test_schemalike.Property]:
name: str
required: bool
multi: bool
typ: tests.test_schemalike.Type
expr: tests.test_schemalike.Expression | None
def get_name(self: Self, *, schema: tests.test_schemalike.Schema) -> str: ...
def get_required(self: Self, *, schema: tests.test_schemalike.Schema) -> bool: ...
def get_multi(self: Self, *, schema: tests.test_schemalike.Schema) -> bool: ...
def get_typ(self: Self, *, schema: tests.test_schemalike.Schema) -> tests.test_schemalike.Type: ...
def get_expr(self: Self, *, schema: tests.test_schemalike.Schema) -> tests.test_schemalike.Expression | None: ...
def get_name({getter_params}) -> str: ...
def get_required({getter_params}) -> bool: ...
def get_multi({getter_params}) -> bool: ...
def get_typ({getter_params}) -> tests.test_schemalike.Type: ...
def get_expr({getter_params}) -> tests.test_schemalike.Expression | None: ...
""")
8 changes: 4 additions & 4 deletions tests/test_type_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@ def test_type_members_func_1():
assert (
str(typ)
== "\
typing.Callable[[\
typemap.typing.Param[typing.Literal['self'], tests.test_type_dir.Base[int], typing.Never], \
typing.Callable[\
typemap.typing.Params[typemap.typing.Param[typing.Literal['self'], tests.test_type_dir.Base[int], typing.Never], \
typemap.typing.Param[typing.Literal['a'], int | None, typing.Never], \
typemap.typing.Param[typing.Literal['b'], int, typing.Literal['keyword', \
'default']]], \
Expand All @@ -403,7 +403,7 @@ def test_type_members_func_2():
assert (
str(typ)
== "\
classmethod[tests.test_type_dir.Base[int], tuple[typemap.typing.Param[typing.Literal['a'], int | None, typing.Never], typemap.typing.Param[typing.Literal['b'], ~K, typing.Never]], dict[str, int]]"
classmethod[tests.test_type_dir.Base[int], typemap.typing.Params[typemap.typing.Param[typing.Literal['a'], int | None, typing.Never], typemap.typing.Param[typing.Literal['b'], ~K, typing.Never]], dict[str, int]]"
)


Expand All @@ -422,7 +422,7 @@ def test_type_members_func_3():
)
assert (
str(evaled)
== "staticmethod[tuple[typemap.typing.Param[typing.Literal['a'], int | typing.Literal['gotcha!'] | Z | None, typing.Never], typemap.typing.Param[typing.Literal['b'], ~K, typing.Never]], dict[str, int | Z]]"
== "staticmethod[typemap.typing.Params[typemap.typing.Param[typing.Literal['a'], int | typing.Literal['gotcha!'] | Z | None, typing.Never], typemap.typing.Param[typing.Literal['b'], ~K, typing.Never]], dict[str, int | Z]]"
)


Expand Down
Loading
Loading