Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[py3] Deprecated StrAndUnicode.

This mix-in is superseded by the @python_2_unicode_compatible decorator.
  • Loading branch information...
commit 4e68e861533846010e372ecf58e3cd0439081754 1 parent d4a0b27
Aymeric Augustin authored
7  django/utils/encoding.py
@@ -8,6 +8,7 @@
8 8
     from urllib.parse import quote
9 9
 except ImportError:     # Python 2
10 10
     from urllib import quote
  11
+import warnings
11 12
 
12 13
 from django.utils.functional import Promise
13 14
 from django.utils import six
@@ -32,6 +33,12 @@ class StrAndUnicode(object):
32 33
     Useful as a mix-in. If you support Python 2 and 3 with a single code base,
33 34
     you can inherit this mix-in and just define __unicode__.
34 35
     """
  36
+    def __init__(self, *args, **kwargs):
  37
+        warnings.warn("StrAndUnicode is deprecated. Define a __str__ method "
  38
+                      "and apply the @python_2_unicode_compatible decorator "
  39
+                      "instead.", PendingDeprecationWarning, stacklevel=2)
  40
+        super(StrAndUnicode, self).__init__(*args, **kwargs)
  41
+
35 42
     if six.PY3:
36 43
         def __str__(self):
37 44
             return self.__unicode__()
7  docs/releases/1.5.txt
@@ -273,3 +273,10 @@ our own copy of ``simplejson``. You can safely change any use of
273 273
 
274 274
 The :func:`~django.utils.itercompat.product` function has been deprecated. Use
275 275
 the built-in :func:`itertools.product` instead.
  276
+
  277
+``django.utils.encoding.StrAndUnicode``
  278
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  279
+
  280
+The :class:`~django.utils.encoding.StrAndUnicode` mix-in has been deprecated.
  281
+Define a ``__str__`` method and apply the
  282
+:func:`~django.utils.encoding.python_2_unicode_compatible` decorator instead.

0 notes on commit 4e68e86

Please sign in to comment.
Something went wrong with that request. Please try again.