Replaced inner functions by class methods.

refs #24031

Thanks to Tim Graham and Michał Modzelewski for the review.
This commit is contained in:
Simon Charette 2015-01-12 19:55:57 -05:00
parent 4832c004e8
commit 47bdad4e6b
2 changed files with 29 additions and 25 deletions

View File

@ -90,22 +90,24 @@ class Q(tree.Node):
clause, _ = query._add_q(self, reuse, allow_joins=allow_joins)
return clause
def refs_aggregate(self, existing_aggregates):
def _refs_aggregate(obj, existing_aggregates):
if not isinstance(obj, tree.Node):
aggregate, aggregate_lookups = refs_aggregate(obj[0].split(LOOKUP_SEP), existing_aggregates)
if not aggregate and hasattr(obj[1], 'refs_aggregate'):
return obj[1].refs_aggregate(existing_aggregates)
@classmethod
def _refs_aggregate(cls, obj, existing_aggregates):
if not isinstance(obj, tree.Node):
aggregate, aggregate_lookups = refs_aggregate(obj[0].split(LOOKUP_SEP), existing_aggregates)
if not aggregate and hasattr(obj[1], 'refs_aggregate'):
return obj[1].refs_aggregate(existing_aggregates)
return aggregate, aggregate_lookups
for c in obj.children:
aggregate, aggregate_lookups = cls._refs_aggregate(c, existing_aggregates)
if aggregate:
return aggregate, aggregate_lookups
for c in obj.children:
aggregate, aggregate_lookups = _refs_aggregate(c, existing_aggregates)
if aggregate:
return aggregate, aggregate_lookups
return False, ()
return False, ()
def refs_aggregate(self, existing_aggregates):
if not existing_aggregates:
return False
return _refs_aggregate(self, existing_aggregates)
return self._refs_aggregate(self, existing_aggregates)
class DeferredAttribute(object):

View File

@ -315,24 +315,26 @@ class WhereNode(tree.Node):
clone.relabel_aliases(change_map)
return clone
@classmethod
def _contains_aggregate(cls, obj):
if not isinstance(obj, tree.Node):
return getattr(obj.lhs, 'contains_aggregate', False) or getattr(obj.rhs, 'contains_aggregate', False)
return any(cls._contains_aggregate(c) for c in obj.children)
@cached_property
def contains_aggregate(self):
def _contains_aggregate(obj):
if not isinstance(obj, tree.Node):
return getattr(obj.lhs, 'contains_aggregate', False) or getattr(obj.rhs, 'contains_aggregate', False)
return any(_contains_aggregate(c) for c in obj.children)
return self._contains_aggregate(self)
return _contains_aggregate(self)
@classmethod
def _refs_field(cls, obj, aggregate_types, field_types):
if not isinstance(obj, tree.Node):
if hasattr(obj.rhs, 'refs_field'):
return obj.rhs.refs_field(aggregate_types, field_types)
return False
return any(cls._refs_field(c, aggregate_types, field_types) for c in obj.children)
def refs_field(self, aggregate_types, field_types):
def _refs_field(obj, aggregate_types, field_types):
if not isinstance(obj, tree.Node):
if hasattr(obj.rhs, 'refs_field'):
return obj.rhs.refs_field(aggregate_types, field_types)
return False
return any(_refs_field(c, aggregate_types, field_types) for c in obj.children)
return _refs_field(self, aggregate_types, field_types)
return self._refs_field(self, aggregate_types, field_types)
class EmptyWhere(WhereNode):