-
-
Notifications
You must be signed in to change notification settings - Fork 308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for typing.Annotated #721
base: master
Are you sure you want to change the base?
Conversation
This addition is really nice! I hope it will be merged |
@TimNekk Agreed! Have been watching this PR for a while now 🍿 |
This would be really nice to have, perhaps it would make a bigger chance of getting merged in this fork: https://github.com/anton-petrov/python-dependency-injector ? |
@4c0n If this commit is used, rather than the copied code, you're welcome. |
@maintain0404 sorry for submitting a review by mistake. I was just checking the changes. I hope your PR get merged soon! However I noticed that your implementation don't support injections into modules and class attributes. The following code should add support for that: def _get_members_and_annotated(obj: Any) -> list[tuple[str, Any]]:
members = inspect.getmembers(obj)
for ann_name, annotation in inspect.get_annotations(obj).items():
if get_origin(annotation) is Annotated:
member = get_args(annotation)[1]
members.append((ann_name, member))
return members And then in def wire( # noqa: C901
container: Container,
*,
modules: Optional[Iterable[ModuleType]] = None,
packages: Optional[Iterable[ModuleType]] = None,
) -> None:
....
for module in modules:
for member_name, member in _get_members_and_annotated(module):
...
elif inspect.isclass(member):
cls = member
try:
cls_members = _get_members_and_annotated(cls)
except Exception: # noqa
# Hotfix, see: https://github.com/ets-labs/python-dependency-injector/issues/441
continue |
Hey, is this dead? Why didn't this get merged? |
Hello, Is there any plan to getting this merge? |
Hey @rmk135, |
Resolve #693.
This PR supports using typing.Annotated instead of parameter defaults when defining markers.