Skip to content

Commit 0ccda57

Browse files
authored
refactoring: ♻️ Little things
1 parent 4759282 commit 0ccda57

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

injection/core/module.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
TypeVar,
2222
cast,
2323
final,
24-
get_origin,
2524
runtime_checkable,
2625
)
2726

@@ -93,7 +92,7 @@ def __iter__(self) -> Iterator[Event]:
9392

9493
@property
9594
def origin(self) -> Event:
96-
return next(self.__iter__())
95+
return next(iter(self))
9796

9897
@property
9998
def is_circular(self) -> bool:
@@ -224,10 +223,7 @@ def notify(self, event: Event):
224223

225224
@staticmethod
226225
def __get_origin(cls: type) -> type:
227-
if origin := get_origin(cls):
228-
return origin
229-
230-
return cls
226+
return getattr(cls, "__origin__", cls)
231227

232228

233229
"""

tests/test_inject.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from dataclasses import dataclass
2-
from typing import Generic, TypeVar
2+
from typing import Annotated, Generic, TypeVar
33

44
import pytest
55

@@ -30,6 +30,13 @@ def my_function(instance: SomeInjectable):
3030

3131
my_function()
3232

33+
def test_inject_with_annotated(self):
34+
@inject
35+
def my_function(instance: Annotated[SomeInjectable, "metadata"]):
36+
assert isinstance(instance, SomeInjectable)
37+
38+
my_function()
39+
3340
def test_inject_with_positional_only_parameter(self):
3441
@inject
3542
def my_function(instance: SomeInjectable, /, **kw):

0 commit comments

Comments
 (0)