Add support for typing.Annotated#721
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 membersAnd 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, |
ZipFile
left a comment
There was a problem hiding this comment.
Looks more or less fine, run black against new code and it is good to go.
|
@ZipFile I can't find black config and version. Is it good to run with latest version and default config? |
|
Latest version of |
|
This comment: #721 (comment) has been addressed in this PR: #889 @abdok96 thank you for bringing this up. |
Seems great! Thanks 🚀 |
Resolve #693.
This PR supports using typing.Annotated instead of parameter defaults when defining markers.