Я нашел решение, использующее лямбда, разместите здесь:
class TestBox:
def __init__(self, func):
self._func = func
def run(self, string):
Checkers.string = string
return self._func()
class Checkers:
string = None
@classmethod
def begin_with(cls, val):
return cls.string.startswith(val)
@classmethod
def end_with(cls, val):
return cls.string.endswith(val)
if __name__ == '__main__':
test_box = TestBox(lambda: Checkers.begin_with("op") or Checkers.end_with("or"))
print(test_box.run("operator")) # True
print(test_box.run("xxtion")) # False
print(test_box.run("xxtionor")) # True