From 94218a49271dadb04ab41527c51994aecbb38fab Mon Sep 17 00:00:00 2001 From: Sean Stewart Date: Wed, 30 Oct 2024 07:53:42 -0400 Subject: [PATCH] fix: extract the real `__value__` from a `TypeAliasType` when calling `origin(...)` --- src/typelib/py/inspection.py | 3 +++ tests/unit/py/test_inspection.py | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/typelib/py/inspection.py b/src/typelib/py/inspection.py index e3d39b7..85a68c6 100644 --- a/src/typelib/py/inspection.py +++ b/src/typelib/py/inspection.py @@ -115,6 +115,9 @@ def origin(annotation: tp.Any) -> tp.Any: a = args(actual) actual = a[0] if a else actual + if istypealiastype(actual): + actual = actual.__value__ + actual = tp.get_origin(actual) or actual # provide defaults for generics diff --git a/tests/unit/py/test_inspection.py b/tests/unit/py/test_inspection.py index 09fd54f..4fbda76 100644 --- a/tests/unit/py/test_inspection.py +++ b/tests/unit/py/test_inspection.py @@ -17,6 +17,7 @@ import types import typing import typing as t +import typing_extensions as te import uuid from unittest import mock @@ -45,6 +46,7 @@ class MyClass: ... user_type=dict(annotation=MyClass, expected=MyClass), class_var_subscripted=dict(annotation=t.ClassVar[str], expected=str), class_var_unsubsripted=dict(annotation=t.ClassVar, expected=t.ClassVar), + type_alias_type=dict(annotation=te.TypeAliasType("T", dict), expected=dict), ) def test_origin(annotation, expected): # When