I came across a bug in my code where an overriding method was hidden because I'd forgotten the @classmethod
decorator. I was wandering if it's possible to force the other way (noted it's probably bad design) but something like:
class Super:
@classmethod
def do_something(cls):
...
class Child:
def do_something(self):
...
obj = Child()
obj.do_something() #calls the child
Child.do_something() #calls the Super method
EDIT: No specific case at the moment but I was wandering if it could hypothetically be done.
As a pure hypothetically application, this could be one way:
class Super:
@classmethod
def do_something(cls):
print('Super doing something')
class Child(Super):
def __init__(self):
self.do_something = lambda: print('Child Doing Something')
Example:
>>> obj = Child()
>>> obj.do_something()
Child Doing Something
>>> Child.do_something()
Super doing something
>>> obj.do_something()
Child Doing Something
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With