If anyone can give me a better way to phrase my question in the title, I'll change it.
I'm using a library1 and from that library I import some high level class:
from library import HighLevelClass
In the library, HighLevelClass
has an attribute which is an instance of another class, and that in turn has an attribute which is an instance of yet another class, and so on...
class Bar():
self.foobar = FooBar()
class Foo():
self.bar = Bar()
class HighLevelClass:
self.foo = Foo()
Now, I want to be able to replace some method of Foo
for instance. I can't just do:
class MyFoo(Foo):
def foo_method(self):
because HighLevelClass
will still be referencing the Foo
in the library, not my Foo
.
I could try to unravel the hierarchy and subclass the HighLevelClass
and make my way down to Foo
subclassing everything as I go, but that's just madness.
What's the correct way to do what I'm trying to achieve?
Footnotes
1 It doesn't really matter for the purposes of the question but here it is: facebookresearch/detectron2
question from:
https://stackoverflow.com/questions/65939062/how-to-subclass-within-a-complicated-hierarchy 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…