Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve typing args when inspecting custom types #687

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 msgspec/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -1002,4 +1002,4 @@ def _translate_inner(
)
return out
else:
return CustomType(t)
return CustomType(t[args] if args else t)
7 changes: 7 additions & 0 deletions tests/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,13 @@ def test_custom():
assert mi.type_info(complex) == mi.CustomType(complex)


def test_custom_with_args():
class MyGeneric(Generic[T]):
value: T

assert mi.type_info(MyGeneric[int]) == mi.CustomType(MyGeneric[int])


@pytest.mark.parametrize(
"kw",
[{}, dict(min_length=0), dict(max_length=3)],
Expand Down