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

__getattr__ typing silences legitimate issues

Open jakub-borusewicz opened this issue 4 months ago • 1 comments

https://github.com/ets-labs/python-dependency-injector/blob/master/src/dependency_injector/containers.pyi#L59

Having

Container:
    
    def __getattr__(self, name: str) -> Provider: ...

in stubs silences cases, when container does not have particular attribute at-all. In my current codebase, I add snippet:

if typing.TYPE_CHECKING:
    from dependency_injector.containers import DeclarativeContainer as DC
    class DeclarativeContainer(DC):
        def __getattr__(self, name: str) -> typing.Never: ...
else:
    from dependency_injector.containers import DeclarativeContainer

to work around it.

Is it necessary to have this method typed like that?

jakub-borusewicz avatar Jul 17 '25 12:07 jakub-borusewicz