summaryrefslogtreecommitdiff
path: root/docs/topics/python3.txt
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2012-11-03 21:43:11 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2012-11-03 22:07:35 +0100
commitfc10418fba4fb906e4265650b62c510d526d63f7 (patch)
treee00dc8dfa531f03a9ba973e4da80d0f796e83733 /docs/topics/python3.txt
parent973f539ab83bb46645f2f711190735c66a246797 (diff)
Fixed #18963 -- Used a subclass-friendly pattern
for Python 2 object model compatibility methods.
Diffstat (limited to 'docs/topics/python3.txt')
-rw-r--r--docs/topics/python3.txt13
1 files changed, 7 insertions, 6 deletions
diff --git a/docs/topics/python3.txt b/docs/topics/python3.txt
index f5749faaf2..e6dc165399 100644
--- a/docs/topics/python3.txt
+++ b/docs/topics/python3.txt
@@ -278,15 +278,13 @@ Iterators
::
- class MyIterator(object):
+ class MyIterator(six.Iterator):
def __iter__(self):
return self # implement some logic here
def __next__(self):
raise StopIteration # implement some logic here
- next = __next__ # Python 2 compatibility
-
Boolean evaluation
~~~~~~~~~~~~~~~~~~
@@ -297,7 +295,8 @@ Boolean evaluation
def __bool__(self):
return True # implement some logic here
- __nonzero__ = __bool__ # Python 2 compatibility
+ def __nonzero__(self): # Python 2 compatibility
+ return type(self).__bool__(self)
Division
~~~~~~~~
@@ -309,12 +308,14 @@ Division
def __truediv__(self, other):
return self / other # implement some logic here
- __div__ = __truediv__ # Python 2 compatibility
+ def __div__(self, other): # Python 2 compatibility
+ return type(self).__truediv__(self, other)
def __itruediv__(self, other):
return self // other # implement some logic here
- __idiv__ = __itruediv__ # Python 2 compatibility
+ def __idiv__(self, other): # Python 2 compatibility
+ return type(self).__itruediv__(self, other)
.. module: django.utils.six