Remove python_2_unicode_compatible method

This commit is contained in:
Bastien Vallet
2020-08-04 14:38:15 +02:00
parent 10f6563852
commit 85469082d0
4 changed files with 0 additions and 26 deletions
-19
View File
@@ -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
-2
View File
@@ -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
-2
View File
@@ -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 """