sdxpy
sdxpy copied to clipboard
Section 4.2: Rethinking
Null
objects must be at the end of the matching chain, i.e., theirrest
must beNone
, so we remove therest
parameter from the class's constructor and passNone
up to the parent constructor every time.
But the code does NOT call the parent constructor at all.
class Null(Match):
def __init__(self):
self.rest = None
Calling with
class Null(Match):
def __init__(self):
super().__init__(None)
does not work either: this would create a new Null()
and recurses endless.
Actually the value self.rest
is never used, so it could be anything. IMHO: Setting the value of None
breaks the class invariant: because of the if
in the constructor the value is never None
. If this classes get more methods this will break and somebody has to keep all the broken parts 😁.