Open macdjord opened 2 months ago
Does it solve your issue if you use body: NoInject[test2.RecursiveDict]
? This is now the recommended way to mark arguments not to be injected.
Does it also work if you flip the order of your decorators? Currently the inject
decorator is executed first, so it has to try to interact everything.
@davidparsson: No, using NoInject[]
does not help.
Does it also work if you flip the order of your decorators? Currently the inject decorator is executed first, so it has to try to interact everything.
You are incorrect. Python decorators are applied bottom-to-top, so @inject
is applied after noninjectable()
in the example.
The way Python decorators work is that this:
@foo_decorator
def bar():
...
Is a syntactic short for for this:
def bar():
...
bar = foo_decorator(bar)
Thus:
@_injector.inject
@_injector.noninjectable('body')
def patch(body: test2.RecursiveDict) -> None:
...
Becomes:
@_injector.noninjectable('body')
def patch(body: test2.RecursiveDict) -> None:
...
patch = _injector.inject(patch)
Becomes:
def patch(body: test2.RecursiveDict) -> None:
...
patch = _injector.noninjectable('body')(patch)
patch = _injector.inject(patch)
You're right, my bad!
Steps To Reproduce
test.py
:test2.py
:Run
test.py
Expected Results
Call proceeds without error
Actual Results
Notes
The error raised in
get_type_hints()
is not Injector's fault; that is a bug in Python itself. However, the fact that Injector fails due to an issue with the type hint of a parameter I explicitly told it not to even try to inject is an Injector issue.