Refs #32948 -- Added Node.__copy__().

This allows the copy.copy() usage in the Q._combine() method to finish
sooner, instead of having to fallback to using the __reduce_ex__(4)
method.

Thia also avoids having to fall into copy.copy() at in Q._combine(),
when combining a Q() with another Q().

Co-authored-by: Keryn Knight <keryn@kerynknight.com>
This commit is contained in:
Nick Pope 2021-07-20 17:23:59 +01:00 committed by Mariusz Felisiak
parent ed9eca8457
commit 19b866c254
2 changed files with 7 additions and 3 deletions

View File

@ -183,9 +183,6 @@ class WhereNode(tree.Node):
clone.relabel_aliases(change_map)
return clone
def copy(self):
return self.clone()
@classmethod
def _contains_aggregate(cls, obj):
if isinstance(obj, tree.Node):

View File

@ -44,6 +44,13 @@ class Node:
def __repr__(self):
return "<%s: %s>" % (self.__class__.__name__, self)
def __copy__(self):
obj = self.create(connector=self.connector, negated=self.negated)
obj.children = self.children # Don't [:] as .__init__() via .create() does.
return obj
copy = __copy__
def __deepcopy__(self, memodict):
obj = self.create(connector=self.connector, negated=self.negated)
obj.children = copy.deepcopy(self.children, memodict)