diff options
| author | Nick Pope <nick@nickpope.me.uk> | 2021-07-20 17:23:59 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-07-27 10:06:24 +0200 |
| commit | 19b866c254b54d904a942f34d662dfacd9005a77 (patch) | |
| tree | 271efd4eda56ed9c63e9c7bddbd43798fe18f900 /django/utils | |
| parent | ed9eca8457e1673d09adfc65392a214027053109 (diff) | |
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>
Diffstat (limited to 'django/utils')
| -rw-r--r-- | django/utils/tree.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/django/utils/tree.py b/django/utils/tree.py index 7ee5b01444..d897cbeacd 100644 --- a/django/utils/tree.py +++ b/django/utils/tree.py @@ -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) |
