-
Notifications
You must be signed in to change notification settings - Fork 26
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
[mypy] Missing positional argument "x" in call to "C" #18
Comments
hi @dosisod, what is the usecase for initialisation I would recommend getting it from di instead, like in the example below: c = di[C] The reason for that is container is quite capable of instantiating complex dependencies with nested structures and by using automated initialisation you possibly cannot make any mistake. Valid reason to instantiate dependencies manually is testing, but in this scenario you should pass all the required dependencies whether they are mocked dependencies or not and probably you shouldn't use DI in that scenario or at least you should mock it. |
I did not know that services that where injected got added to the from kink import di, inject
di["x"] = 42
@inject
class C:
def __init__(self, x: int) -> None:
print(x)
c = di[C]
reveal_type(c)
c2: C = di[C]
reveal_type(c2)
|
@dosisod There are two possible solutions for now:
The way how we use this library is mostly in controllers and dependencies are injected as function's arguments and those have type annotations so mypy handles those gracefully. Our controllers are either executed by framework code or lambda layer in AWS, so again this is outside our project code. I assume creating a mypy plugin to fix this issue shouldn't be a big deal, but at the moment I have couple other priorities so I would appreciate support on this. Eventually you can give it a time and I believe in next couple weeks I might sort it out. |
First of all, thanks for the awesome library! I've tried writing a plugin for I've outlined several possible solutions here: #30 (comment). Please let me know you thoughts! |
This issue is now very much related to #36 |
@skewty I have just seen the issue. I think I will need to spend some time with mypy plugin system, once I get a bit of my life back ^^. I will keep you in the loop. |
I am getting mypy errors when using the
inject
decorator on classes:Running mypy with:
Version info:
The only workaround I can see is this:
Which means the
inject
decorator isn't needed.The text was updated successfully, but these errors were encountered: