Refs #32948 -- Simplified WhereNode and Node.__deepcopy__()/add().
We can use copy() in Node.add() instead of create() as we don't need the children to be cloned via [:] subscript in __init__().
This commit is contained in:
parent
ddf0002bb7
commit
ed9eca8457
|
@ -67,12 +67,12 @@ class WhereNode(tree.Node):
|
|||
else:
|
||||
where_parts.append(c)
|
||||
having_node = (
|
||||
self.__class__(having_parts, self.connector, self.negated)
|
||||
self.create(having_parts, self.connector, self.negated)
|
||||
if having_parts
|
||||
else None
|
||||
)
|
||||
where_node = (
|
||||
self.__class__(where_parts, self.connector, self.negated)
|
||||
self.create(where_parts, self.connector, self.negated)
|
||||
if where_parts
|
||||
else None
|
||||
)
|
||||
|
@ -171,15 +171,10 @@ class WhereNode(tree.Node):
|
|||
self.children[pos] = child.relabeled_clone(change_map)
|
||||
|
||||
def clone(self):
|
||||
clone = self.__class__.create(
|
||||
children=None,
|
||||
connector=self.connector,
|
||||
negated=self.negated,
|
||||
)
|
||||
clone = self.create(connector=self.connector, negated=self.negated)
|
||||
for child in self.children:
|
||||
if hasattr(child, "clone"):
|
||||
clone.children.append(child.clone())
|
||||
else:
|
||||
child = child.clone()
|
||||
clone.children.append(child)
|
||||
return clone
|
||||
|
||||
|
|
|
@ -45,8 +45,7 @@ class Node:
|
|||
return "<%s: %s>" % (self.__class__.__name__, self)
|
||||
|
||||
def __deepcopy__(self, memodict):
|
||||
obj = Node(connector=self.connector, negated=self.negated)
|
||||
obj.__class__ = self.__class__
|
||||
obj = self.create(connector=self.connector, negated=self.negated)
|
||||
obj.children = copy.deepcopy(self.children, memodict)
|
||||
return obj
|
||||
|
||||
|
@ -93,7 +92,7 @@ class Node:
|
|||
node other got squashed or not.
|
||||
"""
|
||||
if self.connector != conn_type:
|
||||
obj = self.create(self.children, self.connector, self.negated)
|
||||
obj = self.copy()
|
||||
self.connector = conn_type
|
||||
self.children = [obj, data]
|
||||
return data
|
||||
|
|
Loading…
Reference in New Issue