summaryrefslogtreecommitdiff
path: root/django/utils
diff options
context:
space:
mode:
Diffstat (limited to 'django/utils')
-rw-r--r--django/utils/tree.py16
1 files changed, 6 insertions, 10 deletions
diff --git a/django/utils/tree.py b/django/utils/tree.py
index f67c90eae4..e82afe9bf7 100644
--- a/django/utils/tree.py
+++ b/django/utils/tree.py
@@ -25,17 +25,13 @@ class Node:
self.connector = connector or self.default
self.negated = negated
- # Required because django.db.models.query_utils.Q. Q. __init__() is
- # problematic, but it is a natural Node subclass in all other respects.
@classmethod
- def _new_instance(cls, children=None, connector=None, negated=False):
+ def create(cls, children=None, connector=None, negated=False):
"""
- Create a new instance of this class when new Nodes (or subclasses) are
- needed in the internal code in this class. Normally, it just shadows
- __init__(). However, subclasses with an __init__ signature that aren't
- an extension of Node.__init__ might need to implement this method to
- allow a Node to create a new instance of them (if they have any extra
- setting up to do).
+ Create a new instance using Node() instead of __init__() as some
+ subclasses, e.g. django.db.models.query_utils.Q, may implement a custom
+ __init__() with a signature that conflicts with the one defined in
+ Node.__init__().
"""
obj = Node(children, connector, negated)
obj.__class__ = cls
@@ -97,7 +93,7 @@ class Node:
node other got squashed or not.
"""
if self.connector != conn_type:
- obj = self._new_instance(self.children, self.connector, self.negated)
+ obj = self.create(self.children, self.connector, self.negated)
self.connector = conn_type
self.children = [obj, data]
return data