I have some object oriented code in Python, where some classes are meant to be extended to provide the missing custom bits of code (a la Template Method pattern, but also with variables), that will only be used by the super class, not by the client code using them.
Are there any style conventions for such abstract (or dull, because their implementation in the super class would be either pass
or raise a NonImplemented
exception) methods and attributes?
I've been browsing the PEP-0008 and it only mentions about prepending an underscore to private members not intended to be used by subclasses.
First of all i think that you are mistaken when you say that:
about prepending underscore to private members not intended to be used by subclasses.
Actually prepending a method/attribute by underscore is a python convention that mean that this method/attribute shouldn't be accessed outside the class (and its subclass) and I think you forgot to read about the double underscore that is used to make a method/attribute not possible to override.
class Foo(object):
def __foo(self):
print "foo"
def main(self):
self.__foo()
class Bar(Foo):
def __foo(self):
print "bar"
bar = Bar()
bar.main()
# This will print "foo" and not "bar".
There is another way of declaring stub method by the way which is using abc.ABCMeta and abc.abstractmethod.