mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-06-17 12:03:13 +03:00
Fix attribute injection with Annotated types
This commit is contained in:
parent
19600d9d08
commit
783b91bf19
|
@ -415,7 +415,7 @@ def wire( # noqa: C901
|
|||
providers_map = ProvidersMap(container)
|
||||
|
||||
for module in modules:
|
||||
for member_name, member in inspect.getmembers(module):
|
||||
for member_name, member in _get_members_and_annotated(module):
|
||||
if _inspect_filter.is_excluded(member):
|
||||
continue
|
||||
|
||||
|
@ -426,7 +426,7 @@ def wire( # noqa: C901
|
|||
elif inspect.isclass(member):
|
||||
cls = member
|
||||
try:
|
||||
cls_members = inspect.getmembers(cls)
|
||||
cls_members = _get_members_and_annotated(cls)
|
||||
except Exception: # noqa
|
||||
# Hotfix, see: https://github.com/ets-labs/python-dependency-injector/issues/441
|
||||
continue
|
||||
|
@ -1025,3 +1025,18 @@ def _get_sync_patched(fn: F, patched: PatchedCallable) -> F:
|
|||
patched.closing,
|
||||
)
|
||||
return cast(F, _patched)
|
||||
|
||||
|
||||
def _get_members_and_annotated(obj: Any) -> list[tuple[str, Any]]:
|
||||
members = inspect.getmembers(obj)
|
||||
try:
|
||||
annotations = inspect.get_annotations(obj)
|
||||
except Exception:
|
||||
annotations = {}
|
||||
for annotation_name, annotation in annotations.items():
|
||||
if get_origin(annotation) is Annotated:
|
||||
args = get_args(annotation)
|
||||
if len(args) > 1:
|
||||
member = args[1]
|
||||
members.append((annotation_name, member))
|
||||
return members
|
||||
|
|
Loading…
Reference in New Issue
Block a user