From 727587c08955e4e42a5b82bfb75d51517b50c976 Mon Sep 17 00:00:00 2001 From: Bendeguz Csirmaz Date: Tue, 10 Sep 2024 23:09:16 +0800 Subject: [PATCH] Refs #373 -- Refactored variable assignments in ColPairs and tuple lookups. --- django/db/models/expressions.py | 4 ++- django/db/models/fields/tuple_lookups.py | 36 ++++++++++++++++-------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py index 154e684ff0..36ff097041 100644 --- a/django/db/models/expressions.py +++ b/django/db/models/expressions.py @@ -1332,7 +1332,9 @@ class Col(Expression): class ColPairs(Expression): def __init__(self, alias, targets, sources, output_field): super().__init__(output_field=output_field) - self.alias, self.targets, self.sources = alias, targets, sources + self.alias = alias + self.targets = targets + self.sources = sources def __len__(self): return len(self.targets) diff --git a/django/db/models/fields/tuple_lookups.py b/django/db/models/fields/tuple_lookups.py index d317a69d43..04c53944dc 100644 --- a/django/db/models/fields/tuple_lookups.py +++ b/django/db/models/fields/tuple_lookups.py @@ -83,12 +83,15 @@ class TupleGreaterThan(TupleLookupMixin, GreaterThan): vals_list = [val for val in self.rhs for _ in range(2)] cols_iter = iter(cols_list[:-1]) vals_iter = iter(vals_list[:-1]) - col, val = next(cols_iter), next(vals_iter) - lookup, connector = next(lookups), next(connectors) + col = next(cols_iter) + val = next(vals_iter) + lookup = next(lookups) + connector = next(connectors) root = node = WhereNode([lookup(col, val)], connector=connector) for col, val in zip(cols_iter, vals_iter): - lookup, connector = next(lookups), next(connectors) + lookup = next(lookups) + connector = next(connectors) child = WhereNode([lookup(col, val)], connector=connector) node.children.append(child) node = child @@ -107,12 +110,15 @@ class TupleGreaterThanOrEqual(TupleLookupMixin, GreaterThanOrEqual): vals_list = [val for val in self.rhs for _ in range(2)] cols_iter = iter(cols_list) vals_iter = iter(vals_list) - col, val = next(cols_iter), next(vals_iter) - lookup, connector = next(lookups), next(connectors) + col = next(cols_iter) + val = next(vals_iter) + lookup = next(lookups) + connector = next(connectors) root = node = WhereNode([lookup(col, val)], connector=connector) for col, val in zip(cols_iter, vals_iter): - lookup, connector = next(lookups), next(connectors) + lookup = next(lookups) + connector = next(connectors) child = WhereNode([lookup(col, val)], connector=connector) node.children.append(child) node = child @@ -131,12 +137,15 @@ class TupleLessThan(TupleLookupMixin, LessThan): vals_list = [val for val in self.rhs for _ in range(2)] cols_iter = iter(cols_list[:-1]) vals_iter = iter(vals_list[:-1]) - col, val = next(cols_iter), next(vals_iter) - lookup, connector = next(lookups), next(connectors) + col = next(cols_iter) + val = next(vals_iter) + lookup = next(lookups) + connector = next(connectors) root = node = WhereNode([lookup(col, val)], connector=connector) for col, val in zip(cols_iter, vals_iter): - lookup, connector = next(lookups), next(connectors) + lookup = next(lookups) + connector = next(connectors) child = WhereNode([lookup(col, val)], connector=connector) node.children.append(child) node = child @@ -155,12 +164,15 @@ class TupleLessThanOrEqual(TupleLookupMixin, LessThanOrEqual): vals_list = [val for val in self.rhs for _ in range(2)] cols_iter = iter(cols_list) vals_iter = iter(vals_list) - col, val = next(cols_iter), next(vals_iter) - lookup, connector = next(lookups), next(connectors) + col = next(cols_iter) + val = next(vals_iter) + lookup = next(lookups) + connector = next(connectors) root = node = WhereNode([lookup(col, val)], connector=connector) for col, val in zip(cols_iter, vals_iter): - lookup, connector = next(lookups), next(connectors) + lookup = next(lookups) + connector = next(connectors) child = WhereNode([lookup(col, val)], connector=connector) node.children.append(child) node = child