kodemore / kink

Dependency injection container made for Python
MIT License
397 stars 25 forks source link

autocomplete not working for injected classes #11

Closed tfriedel closed 3 years ago

tfriedel commented 3 years ago

Thanks for making this nice minimal library! I'm giving it a try for a project currently. One thing I noticed, when I use classes that are decorated with @inject, the autocompletion or display of signature parameters in jupyter notebooks doesn't work. I didn't dive into the source, but maybe you can use some of the suggestions mentioned here: https://hynek.me/articles/decorators/

dkraczkowski commented 3 years ago

@tfriedel I will have a look in my spare time. Thanks for your feedback.

tfriedel commented 3 years ago

I tried

from functools import wraps
...
    @wraps(service)
    def _decorated(*args, **kwargs):
    ...
    @wraps(service)
    async def _async_decorated(*args, **kwargs):

and this solved the problem with autocomplete.

As described in the article, fuctools.wraps still has some shortcomings. I also tried wraps from boltons.functools. The inspection of the decorated function now looked identical to the un-decorated function. But kink didn't auto-inject parameters anymore.

It would be nice to get the added functionality from boltons.functools, but I think using the builtin functools.wraps is already an improvement.

dkraczkowski commented 3 years ago

I didn't have lately much time to look into boltons.functools but will do this at some point. I need to understand how much of a performance impact it can cause and whether it is worth adding it knowing the all the drawbacks (if any). Thank you for your contribution and support.

dkraczkowski commented 3 years ago

The following is reference to the latest build with your fix: https://github.com/kodemore/kink/actions/runs/836243567