Skip to content

Commit

Permalink
Merge pull request #5 from seandstewart/seandstewart/type-alias-type-…
Browse files Browse the repository at this point in the history
…origin

fix: extract the real `__value__` from a `TypeAliasType` when calling `origin(...)`
  • Loading branch information
seandstewart authored Oct 30, 2024
2 parents 85b1d26 + 94218a4 commit e9c0bff
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/typelib/py/inspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/py/test_inspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import types
import typing
import typing as t
import typing_extensions as te
import uuid
from unittest import mock

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e9c0bff

Please sign in to comment.