Created
February 14, 2018 10:34
-
-
Save pavan538/a9c14d66ccd45dcfade92f7a71140280 to your computer and use it in GitHub Desktop.
automatically get docstring of abstract class docstring in derived class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import abc | |
class SuperclassMeta(type): | |
def __new__(mcls, classname, bases, cls_dict): | |
cls = super().__new__(mcls, classname, bases, cls_dict) | |
for name, member in cls_dict.items(): | |
if not getattr(member, '__doc__'): | |
member.__doc__ = getattr(bases[-1], name).__doc__ | |
return cls | |
class Superclass(object, metaclass=SuperclassMeta): | |
"""The one to rule them all""" | |
@abc.abstractmethod | |
def give(self, ring): | |
"""Give out a ring""" | |
pass | |
class Derived(Superclass): | |
"""Somebody has to do the work""" | |
def give(self, ring): | |
print("I pass the ring {} to you".format(ring)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment