python-dependency-injector icon indicating copy to clipboard operation
python-dependency-injector copied to clipboard

type safety for provided?

Open philipbjorge opened this issue 2 years ago • 2 comments
trafficstars

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?

philipbjorge avatar Aug 03 '23 00:08 philipbjorge

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

toinbis avatar Aug 31 '23 12:08 toinbis

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

philipbjorge avatar Sep 08 '23 21:09 philipbjorge