Skip to content
Open
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 rodi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ def _get_obj_locals(obj) -> Optional[Dict[str, Any]]:
return getattr(obj, "_locals", None)


def _get_obj_globals(obj) -> Dict[str, Any]:
return getattr(obj, "_globals", {})


def class_name(input_type):
if input_type in {list, set} and str( # noqa: E721
type(input_type) == "<class 'types.GenericAlias'>"
Expand Down Expand Up @@ -544,9 +548,11 @@ def _resolve_by_init_method(self, context: ResolutionContext):

if sys.version_info >= (3, 10): # pragma: no cover
# Python 3.10
globalns = vars(sys.modules[self.concrete_type.__module__])
globalns.update(_get_obj_globals(self.concrete_type))
annotations = get_type_hints(
self.concrete_type.__init__,
vars(sys.modules[self.concrete_type.__module__]),
globalns,
_get_obj_locals(self.concrete_type),
)
for key, value in params.items():
Expand Down Expand Up @@ -623,9 +629,11 @@ def __call__(self, context: ResolutionContext):
chain.append(concrete_type)

if self._has_default_init():
globalns = vars(sys.modules[concrete_type.__module__])
globalns.update(_get_obj_locals(concrete_type))
annotations = get_type_hints(
concrete_type,
vars(sys.modules[concrete_type.__module__]),
globalns,
_get_obj_locals(concrete_type),
)

Expand Down