question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding type hints to dependency-injector

See original GitHub issue

Hi,

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:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:24 (16 by maintainers)

github_iconTop GitHub Comments

4reactions
rmk135commented, Jul 25, 2020

Got it. Thanks for feedback. Dependency Injector will have typing support.

1reaction
rmk135commented, Oct 28, 2020

@dbertouille , right. I’ll create a separate issue to not make this one endless.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found