From 0ef15d4fa88c5ea8e98a526b4db6c05d54ce6090 Mon Sep 17 00:00:00 2001 From: Dan Watson Date: Wed, 15 May 2024 14:28:54 -0400 Subject: [PATCH] Preserve typing args when inspecting custom types --- msgspec/inspect.py | 2 +- tests/test_inspect.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/msgspec/inspect.py b/msgspec/inspect.py index 2f5a804c..b393c035 100644 --- a/msgspec/inspect.py +++ b/msgspec/inspect.py @@ -1002,4 +1002,4 @@ def _translate_inner( ) return out else: - return CustomType(t) + return CustomType(t[args] if args else t) diff --git a/tests/test_inspect.py b/tests/test_inspect.py index 291fd99c..1b10b52a 100644 --- a/tests/test_inspect.py +++ b/tests/test_inspect.py @@ -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)],