python - Making an overridden abstract method in a subclass "private" -
say have abstract base class, , subclass abstract:
class daemon(object):: __metaclass__ = abc.abcmeta def __init__(self, pid_file): ... @abc.abstractmethod def run(self): return class worker(daemon): __metaclass__ = abc.abcmeta def __init__(self): ... def run(self): # stuff self.process() @abc.abstractmethod def process(self): """ override method when subclassing worker. """ return
when other developers build new actual "working" worker sub-classes, i'd make clear shouldn't mess run method. if use __run
hints method private, i'm creating private abstract method in daemon
, bit confusing. seems odd have protected using _run
because don't want worker sub-classes mess it. realize private , protected names useful conventions in python, want make clear others how build new worker sub-classes.
is there pythonic convention follow in case? or matter of making documentation clear?
you can enforce non-redeclared type of method, although it's hackish : python: enforce class method called within class method?
Comments
Post a Comment