I suspect that the above code has startled many readers. To a typical Python programmer, such heavy use of classes might look entirely contrived — an awkward exercise in trying to make old ideas from the 1980s seem relevant to modern Python.
Indeed, but the solution is not one of the mentioned ones. It is simply functions:
def TextFilter(pattern, text):
return pattern in text
is much simpler. Instantiate with my_filter = functools.partial(TextFilter, 'Error').
Any time you find a class with only two methods, one of which is init, reactor it into a plain function. See also “Stop Writing Classes” on YouTube.
Indeed, but the solution is not one of the mentioned ones. It is simply functions:
is much simpler. Instantiate with
my_filter = functools.partial(TextFilter, 'Error')
.Any time you find a class with only two methods, one of which is init, reactor it into a plain function. See also “Stop Writing Classes” on YouTube.
“Stop Writing Classes” is a recording of a 2012 PyCon talk: https://pyvideo.org/pycon-us-2012/stop-writing-classes.html