1
0
mirror of https://github.com/django/django.git synced 2025-10-28 08:06:09 +00:00

Refs #23919 -- Removed most of remaining six usage

Thanks Tim Graham for the review.
This commit is contained in:
Claude Paroz
2017-01-07 12:11:46 +01:00
parent 7b2f2e74ad
commit 2b281cc35e
180 changed files with 421 additions and 559 deletions

View File

@@ -4,6 +4,7 @@ import warnings
from collections import deque
from contextlib import contextmanager
import _thread
import pytz
from django.conf import settings
@@ -16,7 +17,6 @@ from django.db.transaction import TransactionManagementError
from django.db.utils import DatabaseError, DatabaseErrorWrapper
from django.utils import timezone
from django.utils.functional import cached_property
from django.utils.six.moves import _thread as thread
NO_DB_ALIAS = '__no_db__'
@@ -82,7 +82,7 @@ class BaseDatabaseWrapper(object):
# Thread-safety related attributes.
self.allow_thread_sharing = allow_thread_sharing
self._thread_ident = thread.get_ident()
self._thread_ident = _thread.get_ident()
# A list of no-argument functions to run when the transaction commits.
# Each entry is an (sids, func) tuple, where sids is a set of the
@@ -326,7 +326,7 @@ class BaseDatabaseWrapper(object):
if not self._savepoint_allowed():
return
thread_ident = thread.get_ident()
thread_ident = _thread.get_ident()
tid = str(thread_ident).replace('-', '')
self.savepoint_state += 1
@@ -533,13 +533,13 @@ class BaseDatabaseWrapper(object):
authorized to be shared between threads (via the `allow_thread_sharing`
property). Raises an exception if the validation fails.
"""
if not (self.allow_thread_sharing or self._thread_ident == thread.get_ident()):
if not (self.allow_thread_sharing or self._thread_ident == _thread.get_ident()):
raise DatabaseError(
"DatabaseWrapper objects created in a "
"thread can only be used in that same thread. The object "
"with alias '%s' was created in thread id %s and this is "
"thread id %s."
% (self.alias, self._thread_ident, thread.get_ident())
% (self.alias, self._thread_ident, _thread.get_ident())
)
# ##### Miscellaneous #####

View File

@@ -1,11 +1,10 @@
import sys
from io import StringIO
from django.apps import apps
from django.conf import settings
from django.core import serializers
from django.db import router
from django.utils.six import StringIO
from django.utils.six.moves import input
# The prefix to put on the default database name when creating
# the test database.

View File

@@ -516,7 +516,7 @@ class FormatStylePlaceholderCursor(object):
return CursorIterator(self.cursor)
class CursorIterator(six.Iterator):
class CursorIterator:
"""
Cursor iterator wrapper that invokes our custom row factory.
"""

View File

@@ -5,7 +5,6 @@ from django.db.backends.base.creation import BaseDatabaseCreation
from django.db.utils import DatabaseError
from django.utils.crypto import get_random_string
from django.utils.functional import cached_property
from django.utils.six.moves import input
TEST_DATABASE_PREFIX = 'test_'

View File

@@ -3,7 +3,6 @@ import subprocess
from django.core.files.temp import NamedTemporaryFile
from django.db.backends.base.client import BaseDatabaseClient
from django.utils.six import print_
def _escape_pgpass(txt):
@@ -40,7 +39,7 @@ class DatabaseClient(BaseDatabaseClient):
# Create temporary .pgpass file.
temp_pgpass = NamedTemporaryFile(mode='w+')
try:
print_(
print(
_escape_pgpass(host) or '*',
str(port) or '*',
_escape_pgpass(dbname) or '*',

View File

@@ -5,7 +5,6 @@ import sys
from django.core.exceptions import ImproperlyConfigured
from django.db.backends.base.creation import BaseDatabaseCreation
from django.utils.encoding import force_text
from django.utils.six.moves import input
class DatabaseCreation(BaseDatabaseCreation):

View File

@@ -1,6 +1,6 @@
import os
import sys
from importlib import import_module
from importlib import import_module, reload
from django.apps import apps
from django.conf import settings
@@ -97,7 +97,7 @@ class MigrationLoader(object):
continue
# Force a reload if it's already loaded (tests need this)
if was_loaded:
six.moves.reload_module(module)
reload(module)
self.migrated_apps.add(app_config.label)
directory = os.path.dirname(module.__file__)
# Scan for .py files

View File

@@ -5,7 +5,6 @@ import sys
from django.apps import apps
from django.db.models.fields import NOT_PROVIDED
from django.utils import datetime_safe, timezone
from django.utils.six.moves import input
from .loader import MigrationLoader

View File

@@ -1,3 +1,4 @@
import builtins
import collections
import datetime
import decimal
@@ -10,7 +11,7 @@ from importlib import import_module
from django.db import models
from django.db.migrations.operations.base import Operation
from django.db.migrations.utils import COMPILED_REGEX_TYPE, RegexObject
from django.utils import datetime_safe, six
from django.utils import datetime_safe
from django.utils.encoding import force_text
from django.utils.functional import LazyObject, Promise
from django.utils.timezone import utc
@@ -305,7 +306,7 @@ class TypeSerializer(BaseSerializer):
return string, set(imports)
if hasattr(self.value, "__module__"):
module = self.value.__module__
if module == six.moves.builtins.__name__:
if module == builtins.__name__:
return self.value.__name__, set()
else:
return "%s.%s" % (module, self.value.__name__), {"import %s" % module}

View File

@@ -26,10 +26,8 @@ from django.db.models.signals import (
class_prepared, post_init, post_save, pre_init, pre_save,
)
from django.db.models.utils import make_model_tuple
from django.utils import six
from django.utils.encoding import force_str, force_text
from django.utils.functional import curry
from django.utils.six.moves import zip
from django.utils.text import capfirst, get_text_list
from django.utils.translation import ugettext_lazy as _
from django.utils.version import get_version
@@ -385,7 +383,7 @@ class ModelState(object):
self.adding = True
class Model(six.with_metaclass(ModelBase)):
class Model(metaclass=ModelBase):
def __init__(self, *args, **kwargs):
# Alias some things as locals to avoid repeat global lookups

View File

@@ -3,7 +3,6 @@ from operator import attrgetter
from django.db import IntegrityError, connections, transaction
from django.db.models import signals, sql
from django.utils import six
class ProtectedError(IntegrityError):
@@ -198,7 +197,7 @@ class Collector(object):
# Recursively collect concrete model's parent models, but not their
# related objects. These will be found by meta.get_fields()
concrete_model = model._meta.concrete_model
for ptr in six.itervalues(concrete_model._meta.parents):
for ptr in concrete_model._meta.parents.values():
if ptr:
parent_objs = [getattr(obj, ptr.name) for obj in new_objs]
self.collect(parent_objs, source=model,
@@ -236,7 +235,7 @@ class Collector(object):
)
def instances_with_model(self):
for model, instances in six.iteritems(self.data):
for model, instances in self.data.items():
for obj in instances:
yield model, obj
@@ -285,18 +284,18 @@ class Collector(object):
deleted_counter[qs.model._meta.label] += count
# update fields
for model, instances_for_fieldvalues in six.iteritems(self.field_updates):
for model, instances_for_fieldvalues in self.field_updates.items():
query = sql.UpdateQuery(model)
for (field, value), instances in six.iteritems(instances_for_fieldvalues):
for (field, value), instances in instances_for_fieldvalues.items():
query.update_batch([obj.pk for obj in instances],
{field.name: value}, self.using)
# reverse instance collections
for instances in six.itervalues(self.data):
for instances in self.data.values():
instances.reverse()
# delete instances
for model, instances in six.iteritems(self.data):
for model, instances in self.data.items():
query = sql.DeleteQuery(model)
pk_list = [obj.pk for obj in instances]
count = query.delete_batch(pk_list, self.using)
@@ -309,11 +308,11 @@ class Collector(object):
)
# update collected instances
for model, instances_for_fieldvalues in six.iteritems(self.field_updates):
for (field, value), instances in six.iteritems(instances_for_fieldvalues):
for model, instances_for_fieldvalues in self.field_updates.items():
for (field, value), instances in instances_for_fieldvalues.items():
for obj in instances:
setattr(obj, field.attname, value)
for model, instances in six.iteritems(self.data):
for model, instances in self.data.items():
for instance in instances:
setattr(instance, model._meta.pk.attname, None)
return sum(deleted_counter.values()), dict(deleted_counter)

View File

@@ -10,7 +10,6 @@ from django.db.models.fields import (
)
from django.db.models.query_utils import RegisterLookupMixin
from django.utils.functional import cached_property
from django.utils.six.moves import range
class Lookup(object):

View File

@@ -13,7 +13,6 @@ from django.db.models.fields import AutoField
from django.db.models.fields.proxy import OrderWrt
from django.db.models.fields.related import OneToOneField
from django.db.models.query_utils import PathInfo
from django.utils import six
from django.utils.datastructures import ImmutableList, OrderedSet
from django.utils.deprecation import RemovedInDjango21Warning
from django.utils.encoding import force_text
@@ -228,7 +227,7 @@ class Options(object):
if self.parents:
# Promote the first parent link in lieu of adding yet another
# field.
field = next(six.itervalues(self.parents))
field = next(iter(self.parents.values()))
# Look for a local field with the same name as the
# first parent link. If a local field has already been
# created, use it instead of promoting the parent

View File

@@ -480,7 +480,7 @@ class QuerySet(object):
obj, created = self._create_object_from_params(lookup, params)
if created:
return obj, created
for k, v in six.iteritems(defaults):
for k, v in defaults.items():
setattr(obj, k, v() if callable(v) else v)
obj.save(using=self.db)
return obj, False
@@ -1170,7 +1170,7 @@ class InstanceCheckMeta(type):
return isinstance(instance, QuerySet) and instance.query.is_empty()
class EmptyQuerySet(six.with_metaclass(InstanceCheckMeta)):
class EmptyQuerySet(metaclass=InstanceCheckMeta):
"""
Marker class usable for checking if a queryset is empty by .none():
isinstance(qs.none(), EmptyQuerySet) -> True

View File

@@ -11,7 +11,6 @@ from django.db.models.sql.constants import (
from django.db.models.sql.query import Query, get_order_dir
from django.db.transaction import TransactionManagementError
from django.db.utils import DatabaseError
from django.utils.six.moves import zip
FORCE = object()

View File

@@ -30,7 +30,6 @@ from django.db.models.sql.datastructures import (
from django.db.models.sql.where import (
AND, OR, ExtraWhere, NothingNode, WhereNode,
)
from django.utils import six
from django.utils.encoding import force_text
from django.utils.tree import Node
@@ -104,7 +103,7 @@ class RawQuery(object):
if params_type is tuple:
params = tuple(adapter(val) for val in self.params)
elif params_type is dict:
params = dict((key, adapter(val)) for key, val in six.iteritems(self.params))
params = {key: adapter(val) for key, val in self.params.items()}
else:
raise RuntimeError("Unexpected params type: %s" % params_type)
@@ -665,23 +664,23 @@ class Query(object):
# slight complexity here is handling fields that exist on parent
# models.
workset = {}
for model, values in six.iteritems(seen):
for model, values in seen.items():
for field in model._meta.fields:
if field in values:
continue
m = field.model._meta.concrete_model
add_to_dict(workset, m, field)
for model, values in six.iteritems(must_include):
for model, values in must_include.items():
# If we haven't included a model in workset, we don't add the
# corresponding must_include fields for that model, since an
# empty set means "include all fields". That's why there's no
# "else" branch here.
if model in workset:
workset[model].update(values)
for model, values in six.iteritems(workset):
for model, values in workset.items():
callback(target, model, values)
else:
for model, values in six.iteritems(must_include):
for model, values in must_include.items():
if model in seen:
seen[model].update(values)
else:
@@ -695,7 +694,7 @@ class Query(object):
for model in orig_opts.get_parent_list():
if model not in seen:
seen[model] = set()
for model, values in six.iteritems(seen):
for model, values in seen.items():
callback(target, model, values)
def table_alias(self, table_name, create=False):
@@ -813,7 +812,7 @@ class Query(object):
(key, col.relabeled_clone(change_map)) for key, col in self._annotations.items())
# 2. Rename the alias in the internal table/alias datastructures.
for old_alias, new_alias in six.iteritems(change_map):
for old_alias, new_alias in change_map.items():
if old_alias not in self.alias_map:
continue
alias_data = self.alias_map[old_alias].relabeled_clone(change_map)
@@ -1698,7 +1697,7 @@ class Query(object):
self.group_by.append(col)
if self.annotation_select:
for alias, annotation in six.iteritems(self.annotation_select):
for alias, annotation in self.annotation_select.items():
for col in annotation.get_group_by_cols():
self.group_by.append(col)

View File

@@ -9,7 +9,6 @@ from django.db.models.sql.constants import (
CURSOR, GET_ITERATOR_CHUNK_SIZE, NO_RESULTS,
)
from django.db.models.sql.query import Query
from django.utils import six
__all__ = ['DeleteQuery', 'UpdateQuery', 'InsertQuery', 'AggregateQuery']
@@ -120,7 +119,7 @@ class UpdateQuery(Query):
querysets.
"""
values_seq = []
for name, val in six.iteritems(values):
for name, val in values.items():
field = self.get_meta().get_field(name)
direct = not (field.auto_created and not field.concrete) or not field.concrete
model = field.model._meta.concrete_model
@@ -164,7 +163,7 @@ class UpdateQuery(Query):
if not self.related_updates:
return []
result = []
for model, values in six.iteritems(self.related_updates):
for model, values in self.related_updates.items():
query = UpdateQuery(model)
query.values = values
if self.related_ids is not None: