Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[py3] Replaced __nonzero__ by __bool__

Of course, __nonzero__ alias has been kept for Python 2 compatibility.
  • Loading branch information...
commit 576ec12f8e7024679202b6213b8664ccd8b451b7 1 parent 12cda89
@claudep claudep authored
View
3  django/contrib/auth/context_processors.py
@@ -11,8 +11,9 @@ def __repr__(self):
def __getitem__(self, perm_name):
return self.user.has_perm("%s.%s" % (self.module_name, perm_name))
- def __nonzero__(self):
+ def __bool__(self):
return self.user.has_module_perms(self.module_name)
+ __nonzero__ = __bool__ # Python 2
class PermWrapper(object):
View
6 django/core/files/base.py
@@ -26,8 +26,9 @@ def __unicode__(self):
def __repr__(self):
return "<%s: %s>" % (self.__class__.__name__, self or "None")
- def __nonzero__(self):
+ def __bool__(self):
return bool(self.name)
+ __nonzero__ = __bool__ # Python 2
def __len__(self):
return self.size
@@ -135,8 +136,9 @@ def __init__(self, content, name=None):
def __str__(self):
return 'Raw content'
- def __nonzero__(self):
+ def __bool__(self):
return True
+ __nonzero__ = __bool__ # Python 2
def open(self, mode=None):
self.seek(0)
View
3  django/db/models/query.py
@@ -120,7 +120,7 @@ def _result_iter(self):
if len(self._result_cache) <= pos:
self._fill_cache()
- def __nonzero__(self):
+ def __bool__(self):
if self._prefetch_related_lookups and not self._prefetch_done:
# We need all the results in order to be able to do the prefetch
# in one go. To minimize code duplication, we use the __len__
@@ -134,6 +134,7 @@ def __nonzero__(self):
except StopIteration:
return False
return True
+ __nonzero__ = __bool__ # Python 2
def __contains__(self, val):
# The 'in' operator works without this method, due to __iter__. This
View
3  django/dispatch/saferef.py
@@ -152,9 +152,10 @@ def __str__(self):
__repr__ = __str__
- def __nonzero__( self ):
+ def __bool__( self ):
"""Whether we are still a valid reference"""
return self() is not None
+ __nonzero__ = __bool__ # Python 2
def __eq__(self, other):
"""Compare with another reference"""
View
3  django/forms/formsets.py
@@ -65,9 +65,10 @@ def __getitem__(self, index):
def __len__(self):
return len(self.forms)
- def __nonzero__(self):
+ def __bool__(self):
"""All formsets have a management form which is not included in the length"""
return True
+ __nonzero__ = __bool__ # Python 2
def _management_form(self):
"""Returns the ManagementForm instance for this FormSet."""
View
3  django/utils/tree.py
@@ -68,11 +68,12 @@ def __len__(self):
"""
return len(self.children)
- def __nonzero__(self):
+ def __bool__(self):
"""
For truth value testing.
"""
return bool(self.children)
+ __nonzero__ = __bool__ # Python 2
def __contains__(self, other):
"""
View
2  docs/topics/db/optimization.txt
@@ -230,7 +230,7 @@ It is optimal because:
#. Use of :ttag:`with` means that we store ``user.emails.all`` in a variable
for later use, allowing its cache to be re-used.
-#. The line ``{% if emails %}`` causes ``QuerySet.__nonzero__()`` to be called,
+#. The line ``{% if emails %}`` causes ``QuerySet.__bool__()`` to be called,
which causes the ``user.emails.all()`` query to be run on the database, and
at the least the first line to be turned into an ORM object. If there aren't
any results, it will return False, otherwise True.
Please sign in to comment.
Something went wrong with that request. Please try again.