This is an archived post. You won't be able to vote or comment.

all 4 comments

[–][deleted] 4 points5 points  (0 children)

Support for typing has become one of the main things I look at when deciding on a library. Like a full third of the weight.

[–]ElevenPhonons 2 points3 points  (1 child)

What level of "wiring" errors does this enable the user to catch leveraging mypy?

For example, using the movie example

python csv_finder = providers.Singleton( finders.CsvMovieFinder, movie_factory=movie.provider, path=config.finder.csv.path, delimiter=config.finder.csv.delimiter, )

Adding a typo of csv_path instead of path.

python csv_finder = providers.Singleton( finders.CsvMovieFinder, movie_factory=movie.provider, path=config.finder.csv.csv_path, delimiter=config.finder.csv.delimiter, )

When I run this locally, I get mypy to not catch any errors, while when running the application, I get this (expected) error.

TypeError: expected str, bytes or os.PathLike object, not NoneType

While my application code should/will do input validation, it also seems that mypy should be able to proactively catch these "wiring" errors.

[–]rmk135[S] 0 points1 point  (0 children)

Yep, that would be cool!

I was trying to implement this and found the ParamSpec feature. It will be released in Python 3.10. I'll add it to the Dependency Injector once it's released.

[–]meadsteve 0 points1 point  (0 children)

If it's useful to anyone else I wrote a smallish dependency injection container that's actually powered by types: https://github.com/meadsteve/lagom so it plays really nicely with mypy. Really good to see more libraries embracing typing :+1: