From f3c43ad1fd9556f0fd026a5dfa93c67a5cf186ca Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 19 Nov 2016 21:54:19 +0100 Subject: Refs #23919 -- Removed python_2_unicode_compatible decorator usage --- docs/topics/python3.txt | 21 --------------------- 1 file changed, 21 deletions(-) (limited to 'docs/topics/python3.txt') diff --git a/docs/topics/python3.txt b/docs/topics/python3.txt index 9dd4d83732..5b40f57bd3 100644 --- a/docs/topics/python3.txt +++ b/docs/topics/python3.txt @@ -148,27 +148,6 @@ In Python 3, there's simply :meth:`~object.__str__`, which must return ``str`` (It is also possible to define :meth:`~object.__bytes__`, but Django applications have little use for that method, because they hardly ever deal with ``bytes``.) -Django provides a simple way to define :meth:`~object.__str__` and -` __unicode__()`_ methods that work on Python 2 and 3: you must -define a :meth:`~object.__str__` method returning text and to apply the -:func:`~django.utils.encoding.python_2_unicode_compatible` decorator. - -On Python 3, the decorator is a no-op. On Python 2, it defines appropriate -` __unicode__()`_ and :meth:`~object.__str__` methods (replacing the -original :meth:`~object.__str__` method in the process). Here's an example:: - - from __future__ import unicode_literals - from django.utils.encoding import python_2_unicode_compatible - - @python_2_unicode_compatible - class MyClass(object): - def __str__(self): - return "Instance of my class" - -This technique is the best match for Django's porting philosophy. - -For forwards compatibility, this decorator is available as of Django 1.4.2. - Finally, note that :meth:`~object.__repr__` must return a ``str`` on all versions of Python. -- cgit v1.3