I have a class B that inherits from A :
class A():
def do_something(self, x):
"""Prints x."""
print(x)
class B(A):
def something_else(self, x):
print("This isn't the same.")
I'd like to achieve a few things :
- I'd like for
B.do_somethingto inherit the docstring fromA.do_something. I thinkfunctools.wrapsis the recommended solution : is that right ? Let's say there are some methods of
Athat return an instance ofA. If I call those methods fromB, I'd like them to return an instance ofB. So far, I'm overloading each function manually.def method_of_A(self, *args, **kwargs): return A(super(self.__class__, self).method_of_A(*args, **kwargs))There's likely a better way - especially given that I have to do this for a large number of classes. Is there same way to check if a function is defined within
Band, if not but available inA, have it decorated / wrapped to return an instance ofB? EDIT : I can't make changes toA's codebase.- Are there solutions that are Py2 and Py3 compatible ?
Thanks very much for any suggestions.
Aucun commentaire:
Enregistrer un commentaire