Skip to content
Merged
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
12 changes: 10 additions & 2 deletions injection/_core/common/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,16 @@ def standardize_types(
else:
yield tp

if with_origin and origin is not None:
yield origin
if with_origin:
if origin is not None:
yield origin

for alias in (tp, origin):
if isinstance(alias, TypeAliasType):
yield from standardize_types(
alias.__value__,
with_origin=with_origin,
)

continue

Expand Down
4 changes: 2 additions & 2 deletions injection/_core/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ def __keep_new_record[T](
@staticmethod
def __standardize_inputs[T](
classes: Iterable[InputType[T]],
) -> Iterable[InputType[T]]:
return tuple(standardize_types(*classes, with_origin=True))
) -> Iterator[InputType[T]]:
return standardize_types(*classes, with_origin=True)

@staticmethod
def __update_preprocessing[T](updater: Updater[T]) -> Updater[T]:
Expand Down
21 changes: 21 additions & 0 deletions tests/test_injectable.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,24 @@ def update(self):

a = get_instance(A)
assert isinstance(a, A)

def test_injectable_with_type_alias_type(self):
@injectable
class A: ...

type Alias1 = A
type Alias2 = Alias1

a1 = get_instance(Alias1)
a2 = get_instance(Alias2)
assert isinstance(a1, A)
assert isinstance(a2, A)

def test_injectable_with_generic_type_alias_type(self):
@injectable
class A[T]: ...

type Alias[T] = A[T]

a = get_instance(Alias[int])
assert isinstance(a, A)
Loading