doc: override by derived container class
See original GitHub issueI would like a derived container class to be able to provide a dependency for a base container. It would seem that this isn’t possible now:
class Base(containers.DeclarativeContainer):
to_override = providers.Dependency(instance_of=str)
# method 1 -- override attribute
class Derived1(Base):
other_dependency = providers.Dependency(instance_of=Foo)
to_override = other_dependency.provided.some_string_attr
# method 2 -- use constructor
class Derived2(Base):
def __init__(self, other_dependency: Foo, **kw):
super_kw = kw.copy()
if 'to_override' not in super_kw:
super_kw['to_override'] = other_dependency.some_string_attr
super().__init__(other_dependency=other_dependency, **super_kw)
other_dependency = providers.Dependency(instance_of=Foo)
In either case I get dependency_injector.errors.Error: Dependency is not defined
when I build a derived object and attempt to access to_override
.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Derived class container from base class functions
I want to change the type of objects in a container located in a base class based on its derived type. (so the...
Read more >Container (Java Platform SE 7 ) - Oracle Help Center
As of JDK version 1.1, replaced by doLayout() . Overrides: layout in class Component. isValidateRoot. public boolean isValidateRoot(). Indicates if ...
Read more >Support override keyword on class methods #2000 - GitHub
An override keyword would be immensely useful in typescript. It would be an optional keyword on any method that overrides a super class...
Read more >override specifier (since C++11) - cppreference.com
In a member function declaration or definition, override specifier ensures that the function is virtual and is overriding a virtual function ...
Read more >collections.abc — Abstract Base Classes for Containers ...
This module provides abstract base classes that can be used to test ... The remaining mixin methods come from inheritance and can be...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Added docs for the
@containers.copy()
decorator: https://python-dependency-injector.ets-labs.org/containers/copying.html. Closing the issue.PS: @shaunc , appreciate your review if you would have some time. Please, drop me a line if there are any improvements on your mind.
Hey @shaunc . I’m away from computer right now, will take a look soon.