The author points to this line as the main culprit for self-hell:
self.minimum, self.maximum = min(self.minimum, self.maximum), max(self.minimum, self.maximum)`
This line is needed to 'defensively protect the input'), i.e. try to compensate when minimum and maximum arrive out of order. Firstly, I can't understand exactly why this defensive protection is not done before assigning the attributes, i.e. simply: # not too hellish, more readable on two lines
self.minimum = min(minimum, maximum)
self.maximum = max(minimum, maximum)
Secondly, I'm not very up on my Python Zen, but I think this naming of arguments followed by defensive protection isn't particularly Pythonic anyway. How about something like this? class Window(object):
def __init__(self, x1, x2):
# pass your dimensions in any order
self.minimum = min(x1, x2)
self.maximum = max(x1, x2)
def __call__(self, x):
return self.minimum <= x <= self.maximum