From 8629507edbd67a98df44ebddbf21649d7066f34f Mon Sep 17 00:00:00 2001 From: Jacob Rief Date: Tue, 5 May 2020 01:21:52 +0200 Subject: [PATCH] remove all occurences of six --- shop/admin/notification.py | 3 +-- shop/deferred.py | 5 ++--- shop/models/fields.py | 9 ++------- shop/models/product.py | 1 - shop/money/money_maker.py | 12 ++---------- shop/rest/money.py | 6 ------ shop/serializers/bases.py | 4 +--- shop/templatetags/shop_search_tags.py | 3 +-- 8 files changed, 9 insertions(+), 34 deletions(-) diff --git a/shop/admin/notification.py b/shop/admin/notification.py index 422a0af73..685e9905d 100644 --- a/shop/admin/notification.py +++ b/shop/admin/notification.py @@ -3,7 +3,6 @@ from django.contrib import admin from django.contrib.auth import get_user_model from django.forms import fields, models, widgets -from django.utils import six from django.utils.translation import ugettext_lazy as _ from django_fsm import RETURN_VALUE @@ -43,7 +42,7 @@ def __init__(self, *args, **kwargs): def get_transition_choices(self): choices = OrderedDict() for transition in OrderModel.get_all_transitions(): - if isinstance(transition.target, six.string_types): + if isinstance(transition.target, str): choices[transition.target] = OrderModel.get_transition_name(transition.target) elif isinstance(transition.target, RETURN_VALUE): for target in transition.target.allowed_states: diff --git a/shop/deferred.py b/shop/deferred.py index 9bd267128..effb34228 100644 --- a/shop/deferred.py +++ b/shop/deferred.py @@ -3,7 +3,6 @@ from django.core.exceptions import ImproperlyConfigured from django.db.models.base import ModelBase from django.db import models -from django.utils import six from django.utils.functional import LazyObject, empty from polymorphic.models import PolymorphicModelBase @@ -15,7 +14,7 @@ def __init__(self, to, **kwargs): try: self.abstract_model = to._meta.object_name except AttributeError: - assert isinstance(to, six.string_types), "%s(%r) is invalid. First parameter must be either a model or a model name" % (self.__class__.__name__, to) + assert isinstance(to, str), "%s(%r) is invalid. First parameter must be either a model or a model name" % (self.__class__.__name__, to) self.abstract_model = to self.options = dict(**kwargs) @@ -60,7 +59,7 @@ def __init__(self, to, **kwargs): try: self.abstract_through_model = through._meta.object_name except AttributeError: - assert isinstance(through, six.string_types), ('%s(%r) is invalid. ' + assert isinstance(through, str), ('%s(%r) is invalid. ' 'Through parameter must be either a model or a model name' % (self.__class__.__name__, through)) self.abstract_through_model = through diff --git a/shop/models/fields.py b/shop/models/fields.py index 334ca922e..0acc0c45e 100644 --- a/shop/models/fields.py +++ b/shop/models/fields.py @@ -1,5 +1,4 @@ import enum -import six from django.conf import settings from django.db import models from django.utils.encoding import force_text @@ -30,7 +29,7 @@ def deconstruct(self): class ChoiceEnumMeta(enum.EnumMeta): def __call__(cls, value, *args, **kwargs): - if isinstance(value, string_types): + if isinstance(value, str): try: value = cls.__members__[value] except KeyError: @@ -39,11 +38,7 @@ def __call__(cls, value, *args, **kwargs): def __new__(metacls, classname, bases, classdict): labels = {} - if six.PY2: - member_names = [k for k in classdict.keys() if k not in ['__module__', '__str__', '__doc__']] - else: - member_names = classdict._member_names - for key in member_names: + for key in classdict._member_names: source_value = classdict[key] if isinstance(source_value, (list, tuple)): try: diff --git a/shop/models/product.py b/shop/models/product.py index c9ab1c688..3e15424dd 100644 --- a/shop/models/product.py +++ b/shop/models/product.py @@ -8,7 +8,6 @@ from django.db import models from django.db.models.aggregates import Sum from django.db.models.functions import Coalesce -from django.utils import six from django.utils import timezone from django.utils.encoding import force_text from django.utils.translation import ugettext_lazy as _ diff --git a/shop/money/money_maker.py b/shop/money/money_maker.py index e29d601f1..d1ded9253 100644 --- a/shop/money/money_maker.py +++ b/shop/money/money_maker.py @@ -1,6 +1,5 @@ from decimal import Decimal, InvalidOperation from django.conf import settings -from django.utils import six from django.utils.formats import get_format from django.utils.translation import get_language from cms.utils.helpers import classproperty @@ -33,8 +32,6 @@ def __str__(self): vals.update(amount=Decimal.__str__(Decimal.quantize(self, self._cents))) except InvalidOperation: raise ValueError("Can not represent {} as Money type.".format(self.__repr__())) - if six.PY2: - return u'{:f}'.format(self) return '{:f}'.format(self) def __repr__(self): @@ -182,13 +179,8 @@ def __ge__(self, other, context=None): def __deepcopy__(self, memo): return self.__class__(self._cents) - if six.PY2: - def __nonzero__(self): - return Decimal.__nonzero__(self) and not self.is_nan() - - if six.PY3: - def __bool__(self): - return Decimal.__bool__(self) and not self.is_nan() + def __bool__(self): + return Decimal.__bool__(self) and not self.is_nan() @classproperty def currency(cls): diff --git a/shop/rest/money.py b/shop/rest/money.py index a37975d1e..fdcf3b4a9 100644 --- a/shop/rest/money.py +++ b/shop/rest/money.py @@ -1,5 +1,3 @@ -from django.utils import six - from rest_framework import renderers from rest_framework import serializers from rest_framework.utils import encoders @@ -11,8 +9,6 @@ class JSONEncoder(encoders.JSONEncoder): def default(self, obj): if isinstance(obj, AbstractMoney): - if six.PY2: - return u'{:f}'.format(obj) return '{:f}'.format(obj) return super(JSONEncoder, self).default(obj) @@ -29,6 +25,4 @@ def __init__(self, *args, **kwargs): super(MoneyField, self).__init__(*args, **kwargs) def to_representation(self, obj): - if six.PY2: - return u'{:f}'.format(obj) return '{:f}'.format(obj) diff --git a/shop/serializers/bases.py b/shop/serializers/bases.py index 7eff55943..84817cef0 100644 --- a/shop/serializers/bases.py +++ b/shop/serializers/bases.py @@ -3,10 +3,10 @@ from django.template import TemplateDoesNotExist from django.template.loader import select_template from django.utils.html import strip_spaces_between_tags -from django.utils import six from django.utils.safestring import mark_safe, SafeText from django.utils.translation import get_language_from_request from rest_framework import serializers + from shop.conf import app_settings from shop.models.customer import CustomerModel from shop.models.product import ProductModel @@ -50,8 +50,6 @@ def __init__(self, *args, **kwargs): def get_price(self, product): price = product.get_price(self.context['request']) # TODO: check if this can be simplified using str(product.get_price(...)) - if six.PY2: - return u'{:f}'.format(price) return '{:f}'.format(price) def render_html(self, product, postfix): diff --git a/shop/templatetags/shop_search_tags.py b/shop/templatetags/shop_search_tags.py index f3286e250..cc4f007c7 100644 --- a/shop/templatetags/shop_search_tags.py +++ b/shop/templatetags/shop_search_tags.py @@ -5,7 +5,6 @@ from django.contrib.auth.models import AnonymousUser from django.http.request import HttpRequest from django.utils.html import strip_tags -from django.utils.six import string_types from sekizai.context_processors import sekizai register = template.Library() @@ -34,7 +33,7 @@ def _get_value(self, context, editable=True, **kwargs): placeholder = kwargs.get('placeholder') if not placeholder: return '' - if isinstance(placeholder, string_types): + if isinstance(placeholder, str): placeholder = Placeholder.objects.get(slot=placeholder) content = renderer.render_placeholder( placeholder=placeholder,