mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Refs #23919 -- Removed six.<various>_types usage
Thanks Tim Graham and Simon Charette for the reviews.
This commit is contained in:
@@ -12,7 +12,6 @@ from django.db.migrations.questioner import MigrationQuestioner
|
||||
from django.db.migrations.utils import (
|
||||
COMPILED_REGEX_TYPE, RegexObject, get_migration_name_timestamp,
|
||||
)
|
||||
from django.utils import six
|
||||
|
||||
from .topological_sort import stable_topological_sort
|
||||
|
||||
@@ -538,7 +537,7 @@ class MigrationAutodetector(object):
|
||||
]
|
||||
# Depend on all bases
|
||||
for base in model_state.bases:
|
||||
if isinstance(base, six.string_types) and "." in base:
|
||||
if isinstance(base, str) and "." in base:
|
||||
base_app_label, base_name = base.split(".", 1)
|
||||
dependencies.append((base_app_label, base_name, None, True))
|
||||
# Depend on the other end of the primary key if it's a relation
|
||||
@@ -659,7 +658,7 @@ class MigrationAutodetector(object):
|
||||
]
|
||||
# Depend on all bases
|
||||
for base in model_state.bases:
|
||||
if isinstance(base, six.string_types) and "." in base:
|
||||
if isinstance(base, str) and "." in base:
|
||||
base_app_label, base_name = base.split(".", 1)
|
||||
dependencies.append((base_app_label, base_name, None, True))
|
||||
# Generate creation operation
|
||||
|
||||
@@ -3,7 +3,6 @@ from django.db.migrations.operations.base import Operation
|
||||
from django.db.migrations.state import ModelState
|
||||
from django.db.models.fields.related import RECURSIVE_RELATIONSHIP_CONSTANT
|
||||
from django.db.models.options import normalize_together
|
||||
from django.utils import six
|
||||
from django.utils.functional import cached_property
|
||||
|
||||
from .fields import (
|
||||
@@ -57,7 +56,7 @@ class CreateModel(ModelOperation):
|
||||
_check_for_duplicates('fields', (name for name, _ in self.fields))
|
||||
_check_for_duplicates('bases', (
|
||||
base._meta.label_lower if hasattr(base, '_meta') else
|
||||
base.lower() if isinstance(base, six.string_types) else base
|
||||
base.lower() if isinstance(base, str) else base
|
||||
for base in self.bases
|
||||
))
|
||||
_check_for_duplicates('managers', (name for name, _ in self.managers))
|
||||
@@ -110,7 +109,7 @@ class CreateModel(ModelOperation):
|
||||
# Check we didn't inherit from the model
|
||||
models_to_check = [
|
||||
base for base in self.bases
|
||||
if base is not models.Model and isinstance(base, (models.base.ModelBase, six.string_types))
|
||||
if base is not models.Model and isinstance(base, (models.base.ModelBase, str))
|
||||
]
|
||||
# Check we have no FKs/M2Ms with it
|
||||
for fname, field in self.fields:
|
||||
@@ -129,7 +128,7 @@ class CreateModel(ModelOperation):
|
||||
Take either a model class or an "app_label.ModelName" string
|
||||
and return (app_label, object_name).
|
||||
"""
|
||||
if isinstance(model, six.string_types):
|
||||
if isinstance(model, str):
|
||||
return model.split(".", 1)
|
||||
else:
|
||||
return model._meta.app_label, model._meta.object_name
|
||||
|
||||
@@ -362,11 +362,11 @@ def serializer_factory(value):
|
||||
return SettingsReferenceSerializer(value)
|
||||
if isinstance(value, float):
|
||||
return FloatSerializer(value)
|
||||
if isinstance(value, six.integer_types + (bool, type(None))):
|
||||
if isinstance(value, (bool, int, type(None))):
|
||||
return BaseSimpleSerializer(value)
|
||||
if isinstance(value, six.binary_type):
|
||||
if isinstance(value, bytes):
|
||||
return ByteTypeSerializer(value)
|
||||
if isinstance(value, six.text_type):
|
||||
if isinstance(value, str):
|
||||
return TextTypeSerializer(value)
|
||||
if isinstance(value, decimal.Decimal):
|
||||
return DecimalSerializer(value)
|
||||
|
||||
@@ -10,7 +10,6 @@ from django.db.models.fields.proxy import OrderWrt
|
||||
from django.db.models.fields.related import RECURSIVE_RELATIONSHIP_CONSTANT
|
||||
from django.db.models.options import DEFAULT_NAMES, normalize_together
|
||||
from django.db.models.utils import make_model_tuple
|
||||
from django.utils import six
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.module_loading import import_string
|
||||
@@ -20,7 +19,7 @@ from .exceptions import InvalidBasesError
|
||||
|
||||
|
||||
def _get_app_label_and_model_name(model, app_label=''):
|
||||
if isinstance(model, six.string_types):
|
||||
if isinstance(model, str):
|
||||
split = model.split('.', 1)
|
||||
return (tuple(split) if len(split) == 2 else (app_label, split[0]))
|
||||
else:
|
||||
@@ -37,7 +36,7 @@ def _get_related_models(m):
|
||||
]
|
||||
related_fields_models = set()
|
||||
for f in m._meta.get_fields(include_parents=True, include_hidden=True):
|
||||
if f.is_relation and f.related_model is not None and not isinstance(f.related_model, six.string_types):
|
||||
if f.is_relation and f.related_model is not None and not isinstance(f.related_model, str):
|
||||
related_fields_models.add(f.model)
|
||||
related_models.append(f.related_model)
|
||||
# Reverse accessors of foreign keys to proxy models are attached to their
|
||||
@@ -458,7 +457,7 @@ class ModelState(object):
|
||||
options[name] = set(normalize_together(it))
|
||||
else:
|
||||
options[name] = model._meta.original_attrs[name]
|
||||
# Force-convert all options to text_type (#23226)
|
||||
# Force-convert all options to str (#23226)
|
||||
options = cls.force_text_recursive(options)
|
||||
# If we're ignoring relationships, remove all field-listing model
|
||||
# options (that option basically just means "make a stub model")
|
||||
@@ -496,7 +495,7 @@ class ModelState(object):
|
||||
for base in flattened_bases
|
||||
)
|
||||
# Ensure at least one base inherits from models.Model
|
||||
if not any((isinstance(base, six.string_types) or issubclass(base, models.Model)) for base in bases):
|
||||
if not any((isinstance(base, str) or issubclass(base, models.Model)) for base in bases):
|
||||
bases = (models.Model,)
|
||||
|
||||
managers = []
|
||||
@@ -539,9 +538,7 @@ class ModelState(object):
|
||||
|
||||
@classmethod
|
||||
def force_text_recursive(cls, value):
|
||||
if isinstance(value, six.string_types):
|
||||
return force_text(value)
|
||||
elif isinstance(value, list):
|
||||
if isinstance(value, list):
|
||||
return [cls.force_text_recursive(x) for x in value]
|
||||
elif isinstance(value, tuple):
|
||||
return tuple(cls.force_text_recursive(x) for x in value)
|
||||
@@ -588,7 +585,7 @@ class ModelState(object):
|
||||
# Then, work out our bases
|
||||
try:
|
||||
bases = tuple(
|
||||
(apps.get_model(base) if isinstance(base, six.string_types) else base)
|
||||
(apps.get_model(base) if isinstance(base, str) else base)
|
||||
for base in self.bases
|
||||
)
|
||||
except LookupError:
|
||||
|
||||
Reference in New Issue
Block a user