Skip to content

Commit e9c0bff

Browse files
authored
Merge pull request #5 from seandstewart/seandstewart/type-alias-type-origin
fix: extract the real `__value__` from a `TypeAliasType` when calling `origin(...)`
2 parents 85b1d26 + 94218a4 commit e9c0bff

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/typelib/py/inspection.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ def origin(annotation: tp.Any) -> tp.Any:
115115
a = args(actual)
116116
actual = a[0] if a else actual
117117

118+
if istypealiastype(actual):
119+
actual = actual.__value__
120+
118121
actual = tp.get_origin(actual) or actual
119122

120123
# provide defaults for generics

tests/unit/py/test_inspection.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import types
1818
import typing
1919
import typing as t
20+
import typing_extensions as te
2021
import uuid
2122
from unittest import mock
2223

@@ -45,6 +46,7 @@ class MyClass: ...
4546
user_type=dict(annotation=MyClass, expected=MyClass),
4647
class_var_subscripted=dict(annotation=t.ClassVar[str], expected=str),
4748
class_var_unsubsripted=dict(annotation=t.ClassVar, expected=t.ClassVar),
49+
type_alias_type=dict(annotation=te.TypeAliasType("T", dict), expected=dict),
4850
)
4951
def test_origin(annotation, expected):
5052
# When

0 commit comments

Comments
 (0)