From 85469082d0dcfac04ee92d205d8bee1a4c3aef4d Mon Sep 17 00:00:00 2001 From: Bastien Vallet Date: Tue, 4 Aug 2020 14:38:15 +0200 Subject: [PATCH] Remove python_2_unicode_compatible method --- example/orders/models.py | 3 --- polymorphic/compat.py | 19 ------------------- polymorphic/managers.py | 2 -- polymorphic/showfields.py | 2 -- 4 files changed, 26 deletions(-) diff --git a/example/orders/models.py b/example/orders/models.py index cf12286..97ec22e 100644 --- a/example/orders/models.py +++ b/example/orders/models.py @@ -1,12 +1,10 @@ from django.db import models from django.utils.dates import MONTHS_3 -from django.utils.six import python_2_unicode_compatible from django.utils.translation import ugettext_lazy as _ from polymorphic.models import PolymorphicModel -@python_2_unicode_compatible class Order(models.Model): """ An example order that has polymorphic relations @@ -23,7 +21,6 @@ class Order(models.Model): return self.title -@python_2_unicode_compatible class Payment(PolymorphicModel): """ A generic payment model. diff --git a/polymorphic/compat.py b/polymorphic/compat.py index e52a3a9..094b161 100644 --- a/polymorphic/compat.py +++ b/polymorphic/compat.py @@ -24,22 +24,3 @@ def with_metaclass(meta, *bases): return meta(name, bases, d) return type.__new__(metaclass, "temporary_class", (), {}) - - -def python_2_unicode_compatible(klass): - """ - A decorator that defines __unicode__ and __str__ methods under Python 2. - Under Python 3 it does nothing. - - To support Python 2 and 3 with a single code base, define a __str__ method - returning text and apply this decorator to the class. - """ - if PY2: - if "__str__" not in klass.__dict__: - raise ValueError( - "@python_2_unicode_compatible cannot be applied " - "to %s because it doesn't define __str__()." % klass.__name__ - ) - klass.__unicode__ = klass.__str__ - klass.__str__ = lambda self: self.__unicode__().encode("utf-8") - return klass diff --git a/polymorphic/managers.py b/polymorphic/managers.py index a43840b..901f086 100644 --- a/polymorphic/managers.py +++ b/polymorphic/managers.py @@ -6,13 +6,11 @@ from __future__ import unicode_literals from django.db import models -from polymorphic.compat import python_2_unicode_compatible from polymorphic.query import PolymorphicQuerySet __all__ = ("PolymorphicManager", "PolymorphicQuerySet") -@python_2_unicode_compatible class PolymorphicManager(models.Manager): """ Manager for PolymorphicModel diff --git a/polymorphic/showfields.py b/polymorphic/showfields.py index ffa14f5..0d62d88 100644 --- a/polymorphic/showfields.py +++ b/polymorphic/showfields.py @@ -4,12 +4,10 @@ import re from django.db import models from . import compat -from .compat import python_2_unicode_compatible RE_DEFERRED = re.compile("_Deferred_.*") -@python_2_unicode_compatible class ShowFieldBase(object): """ base class for the ShowField... model mixins, does the work """