Open li-dennis opened 3 years ago
Hi Dennis,
Could you give some examples, please?
@ivankorobkov
@inject.autoparams()
def refresh_cache(cache: RedisCache):
pass
....
refresh_cache()
gives the error
Argument missing for parameter "cache"
Hi, this is definitely a problem for projects that use mypy and type linters. With these linters getting more popular, is there any suggestion how to make this library compatible? Wrapping in Optional[] is not really a great solution, because it forces checks for non None when the injected value is used.
Hi @fibigerg
Thank for you comment.
I have very little knowledge about mypy or type linters. If some can find a solution and will make a PR, I will gladly merge it and release the next version.
Any updates with this?
Hi,
We've been making use of your library quite a lot and it's been a joy to use! The only challenge I've really run into is handling pyright/mypy errors with the
@inject
decorator. The decorator of course modifies the type signature of the function/classes, but pyright, mypy, pylint etc don't really have knowledge of this so they throw warnings that certain parameters are missing.Are there any workarounds to this? I've been trying to figure something out but so far it seems like the likely answer is "no". This is the closest https://github.com/microsoft/pyright/issues/774
Other than that the only ideas I've come up is converting the injected parameters from required to optional. But that's a less than ideal solution since often time these are classes which can be expensive to instantiate, and performance matters for my application.
Best