summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuel Ferdman <emmanuelferdman@gmail.com>2026-03-13 01:57:41 +0200
committerGitHub <noreply@github.com>2026-03-12 19:57:41 -0400
commit7cb2221e9267dec3f1cf7c88b8686d38fd956639 (patch)
tree91c3327cbcea6d46df485aad5a2c2321563c4ee6
parent3180ddb3f532ef246d318d64225886b7c0593676 (diff)
Encapsulated loop logic to avoid leaking module-level variables.
-rw-r--r--django/db/models/expressions.py12
-rw-r--r--django/template/smartif.py10
2 files changed, 15 insertions, 7 deletions
diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py
index 9d3c1241e7..9c734c60a1 100644
--- a/django/db/models/expressions.py
+++ b/django/db/models/expressions.py
@@ -705,10 +705,14 @@ def register_combinable_fields(lhs, connector, rhs, result):
_connector_combinators[connector].append((lhs, rhs, result))
-for d in _connector_combinations:
- for connector, field_types in d.items():
- for lhs, rhs, result in field_types:
- register_combinable_fields(lhs, connector, rhs, result)
+def _register_combinable_fields():
+ for d in _connector_combinations:
+ for connector, field_types in d.items():
+ for lhs, rhs, result in field_types:
+ register_combinable_fields(lhs, connector, rhs, result)
+
+
+_register_combinable_fields()
@functools.lru_cache(maxsize=128)
diff --git a/django/template/smartif.py b/django/template/smartif.py
index c0682f3b1e..ad4d01f898 100644
--- a/django/template/smartif.py
+++ b/django/template/smartif.py
@@ -111,10 +111,14 @@ OPERATORS = {
"<=": infix(10, lambda context, x, y: x.eval(context) <= y.eval(context)),
}
+
# Assign 'id' to each:
-for key, op in OPERATORS.items():
- op.id = key
-del key, op
+def _init_operators():
+ for key, op in OPERATORS.items():
+ op.id = key
+
+
+_init_operators()
class Literal(TokenBase):