Adding type hints to dependency-injector
See original GitHub issueHi,
Now that python typing (type hints) is very common, it would be great that dependency-injector will have type hints / annotations. Currently when using Container / Provider classes mypy complains since it doesn’t have information about a provider returned type, etc.
For example:
provider: Provider[Animal] = providers.Factory(Cat)
animal = provider() # mypy can know that animal is of type Animal
My current workaround is to put type: ignore
in many places but it is less desired since I won’t get errors at type checking time.
Thanks
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:24 (16 by maintainers)
Top Results From Across the Web
Type annotations in dependency injection - Webinterpret Tech
Simpler configuration with Injector! After adding the type hints we were freed from tracing our dependencies manually.
Read more >How to Do Dependency Injection Using Python Type Hints
Python type annotations can be used to inject dependencies. Here is how. Some python code using DI with type hints. Why Dependency Injection...
Read more >Typing and mypy — Dependency Injector 4.41.0 documentation
Dependency Injector providers are mypy-friendly. Providers module goes with the typing stubs to provide the typing information to ``mypy``, IDEs and ...
Read more >Difference between Dependency Injection , Type Hinting and ...
Type hinting is instrumental of the two others and consists of typing an argument in a declaration: · Dependency injection relies on the ......
Read more >Dependency injection with Hilt | Android Developers
As a best practice, if you add a qualifier to a type, add qualifiers to all the possible ways to provide that dependency....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Got it. Thanks for feedback. Dependency Injector will have typing support.
@dbertouille , right. I’ll create a separate issue to not make this one endless.