From 7be94e033557ec984f53f8a67bd3326ee5a83b4a Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Thu, 27 Apr 2017 05:16:19 -0700 Subject: [PATCH] Replaced set |= operator with update() to avoid temporary set. --- django/db/models/base.py | 2 +- django/db/models/sql/query.py | 2 +- django/test/utils.py | 7 ++----- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/django/db/models/base.py b/django/db/models/base.py index 3c1cb9a1198..28c26990439 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -204,7 +204,7 @@ class ModelBase(type): if base not in parents or not hasattr(base, '_meta'): # Things without _meta aren't functional models, so they're # uninteresting parents. - inherited_attributes |= set(base.__dict__.keys()) + inherited_attributes.update(base.__dict__) continue parent_fields = base._meta.local_fields + base._meta.local_many_to_many diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 5c3eca0032b..a1c1c4be384 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -1017,7 +1017,7 @@ class Query: ) # The used_joins for a tuple of expressions is the union of # the used_joins for the individual expressions. - used_joins |= set(k for k, v in self.alias_refcount.items() if v > pre_joins.get(k, 0)) + used_joins.update(k for k, v in self.alias_refcount.items() if v > pre_joins.get(k, 0)) # For Oracle '' is equivalent to null. The check needs to be done # at this stage because join promotion can't be done at compiler # stage. Using DEFAULT_DB_ALIAS isn't nice, but it is the best we diff --git a/django/test/utils.py b/django/test/utils.py index efd1b49c88f..9ba24a3e77a 100644 --- a/django/test/utils.py +++ b/django/test/utils.py @@ -7,6 +7,7 @@ import warnings from contextlib import contextmanager from functools import wraps from io import StringIO +from itertools import chain from types import SimpleNamespace from unittest import TestCase, skipIf, skipUnless from xml.dom.minidom import Node, parseString @@ -85,11 +86,7 @@ class ContextList(list): """ Flattened keys of subcontexts. """ - keys = set() - for subcontext in self: - for dict in subcontext: - keys |= set(dict.keys()) - return keys + return set(chain.from_iterable(d for subcontext in self for d in subcontext)) def instrumented_test_render(self, context):