ets-labs / python-dependency-injector

Dependency injection framework for Python
https://python-dependency-injector.ets-labs.org/
BSD 3-Clause "New" or "Revised" License
3.88k stars 303 forks source link

type safety for provided? #731

Open philipbjorge opened 1 year ago

philipbjorge commented 1 year ago

When referencing a singleton via foo.provided.bar, we lose type safety because provided always resolves to the ProvidedInstance rather than the specific type of the dependency.

    settings = providers.Singleton(Settings)

    identity_container = providers.Container(
        IdentityContainer,
        base_url=settings.provided.IDENTITY_SERVICE_BASE_URL,
    )

Expected settings.provided resolves to Settings

Actual settings.provided resolves to ProvidedInstance

This seems like an easy change to make -- Is there any reason this wouldn't work if I opened a PR?

toinbis commented 1 year ago

@philipbjorge - installed your fix from git, works like magic! @rmk135 is there any chance we could get it merge?

philipbjorge commented 1 year ago

@toinbis -- Another type update :) https://github.com/ets-labs/python-dependency-injector/pull/744