You want "polymorphism"? I think your code can be simplified a little:
class Executor:
def execute(self, spec):
if spec.print:
self._print(spec)
if spec.run:
self._run(spec)
if not (spec.run or spec.print):
self.skip(spec)
def _run(self, spec):
def _print(self, spec):
def _skip(self, spec):
Executor().execute(spec)
But that's not really polymorphism.
You seem to know a lot about the spec object. You say:
I have lots of if elif statements in order to know what specification is passed
So do you have the ability to change implementation of spec or pass in a subclass of spec? It seems to know if it wants to print, run, or skip:
class Executor:
def execute(self, spec):
spec.print(self)
spec.run(self)
spec.skip(self)
Executor().execute(spec)
If you can instantiate your Executor based on the decisions made by spec
you can "simplify" with subclasses:
from abc import ABC, abstractmethod
class ExecutorMixin(ABC):
__slots__ = ()
@abstractmethod
def execute(self):
raise NotImplementedError
def _run(self, spec):
...
def _print(self, spec):
...
def _skip(self, spec):
...
ExecutorMixin
is an interface that you can subclass with the specific behavior and do your operation based on the type of Executor:
class ExecutorPrintAndRun(ExecutorMixin):
def execute(self, spec):
self._print(spec)
self._run(spec)
class ExecutorRun(ExecutorMixin):
def execute(self, spec):
self._run(spec)
class ExecutorPrint(ExecutorMixin):
def execute(self, spec):
self._print(spec)
class ExecutorSkip(ExecutorMixin):
def execute(self, spec):
self._skip(spec)
Then you instantiate the class you want to use:
ExecutorSkip().execute(spec)