summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2017-01-19 09:55:03 -0500
committerSimon Charette <charette.s@gmail.com>2017-01-19 11:26:26 -0500
commit4c5ed3e683576ece880ae99398a1e7d8c5829617 (patch)
treeb9af0b5941e9f0ef242bcbd36ee8443f91a5323b
parent53f3d53ed413d44c88d7e83ee11cff113e84ff4d (diff)
Refs #23919 -- Removed __nonzero__() methods (for Python 2).
Thanks Tim for the review.
-rw-r--r--django/contrib/auth/context_processors.py3
-rw-r--r--django/contrib/gis/measure.py3
-rw-r--r--django/core/files/base.py6
-rw-r--r--django/db/models/query.py3
-rw-r--r--django/forms/formsets.py3
-rw-r--r--django/utils/datastructures.py3
-rw-r--r--django/utils/translation/__init__.py3
-rw-r--r--django/utils/tree.py3
-rw-r--r--tests/generic_relations_regress/models.py5
-rw-r--r--tests/generic_relations_regress/tests.py10
10 files changed, 8 insertions, 34 deletions
diff --git a/django/contrib/auth/context_processors.py b/django/contrib/auth/context_processors.py
index f865fc1b7d..1938568401 100644
--- a/django/contrib/auth/context_processors.py
+++ b/django/contrib/auth/context_processors.py
@@ -20,9 +20,6 @@ class PermLookupDict:
def __bool__(self):
return self.user.has_module_perms(self.app_label)
- def __nonzero__(self): # Python 2 compatibility
- return type(self).__bool__(self)
-
class PermWrapper:
def __init__(self, user):
diff --git a/django/contrib/gis/measure.py b/django/contrib/gis/measure.py
index bc426b597b..fa3d7c34f2 100644
--- a/django/contrib/gis/measure.py
+++ b/django/contrib/gis/measure.py
@@ -175,9 +175,6 @@ class MeasureBase:
def __bool__(self):
return bool(self.standard)
- def __nonzero__(self): # Python 2 compatibility
- return type(self).__bool__(self)
-
def default_units(self, kwargs):
"""
Return the unit value and the default units specified
diff --git a/django/core/files/base.py b/django/core/files/base.py
index df29c94eee..0834c56b8d 100644
--- a/django/core/files/base.py
+++ b/django/core/files/base.py
@@ -25,9 +25,6 @@ class File(FileProxyMixin):
def __bool__(self):
return bool(self.name)
- def __nonzero__(self): # Python 2 compatibility
- return type(self).__bool__(self)
-
def __len__(self):
return self.size
@@ -149,9 +146,6 @@ class ContentFile(File):
def __bool__(self):
return True
- def __nonzero__(self): # Python 2 compatibility
- return type(self).__bool__(self)
-
def open(self, mode=None):
self.seek(0)
diff --git a/django/db/models/query.py b/django/db/models/query.py
index b536521fa4..f4d56a269b 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -253,9 +253,6 @@ class QuerySet:
self._fetch_all()
return bool(self._result_cache)
- def __nonzero__(self): # Python 2 compatibility
- return type(self).__bool__(self)
-
def __getitem__(self, k):
"""
Retrieves an item or slice from the set of results.
diff --git a/django/forms/formsets.py b/django/forms/formsets.py
index 18a8cabefa..1afb72fb85 100644
--- a/django/forms/formsets.py
+++ b/django/forms/formsets.py
@@ -78,9 +78,6 @@ class BaseFormSet:
"""All formsets have a management form which is not included in the length"""
return True
- def __nonzero__(self): # Python 2 compatibility
- return type(self).__bool__(self)
-
@cached_property
def management_form(self):
"""Returns the ManagementForm instance for this FormSet."""
diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py
index a89af1780b..a61a445ab0 100644
--- a/django/utils/datastructures.py
+++ b/django/utils/datastructures.py
@@ -32,9 +32,6 @@ class OrderedSet:
def __bool__(self):
return bool(self.dict)
- def __nonzero__(self): # Python 2 compatibility
- return type(self).__bool__(self)
-
def __len__(self):
return len(self.dict)
diff --git a/django/utils/translation/__init__.py b/django/utils/translation/__init__.py
index 4dc4c16c28..a8f3b751b4 100644
--- a/django/utils/translation/__init__.py
+++ b/django/utils/translation/__init__.py
@@ -114,9 +114,6 @@ def lazy_number(func, resultclass, number=None, **kwargs):
def __bool__(self):
return bool(kwargs['singular'])
- def __nonzero__(self): # Python 2 compatibility
- return type(self).__bool__(self)
-
def __mod__(self, rhs):
if isinstance(rhs, dict) and number:
try:
diff --git a/django/utils/tree.py b/django/utils/tree.py
index 2c8ab3fe1c..5c86e73da8 100644
--- a/django/utils/tree.py
+++ b/django/utils/tree.py
@@ -71,9 +71,6 @@ class Node:
"""
return bool(self.children)
- def __nonzero__(self): # Python 2 compatibility
- return type(self).__bool__(self)
-
def __contains__(self, other):
"""
Returns True is 'other' is a direct child of this instance.
diff --git a/tests/generic_relations_regress/models.py b/tests/generic_relations_regress/models.py
index d9cf692b75..fae8aadaa5 100644
--- a/tests/generic_relations_regress/models.py
+++ b/tests/generic_relations_regress/models.py
@@ -121,9 +121,8 @@ class Guild(models.Model):
name = models.CharField(max_length=15)
members = models.ManyToManyField(Developer)
- def __nonzero__(self):
-
- return self.members.count()
+ def __bool__(self):
+ return False
class Tag(models.Model):
diff --git a/tests/generic_relations_regress/tests.py b/tests/generic_relations_regress/tests.py
index d3986b6916..0dac7040e4 100644
--- a/tests/generic_relations_regress/tests.py
+++ b/tests/generic_relations_regress/tests.py
@@ -119,10 +119,12 @@ class GenericRelationTests(TestCase):
note = Note(note='Deserve a bonus', content_object=team1)
note.save()
- def test_target_model_nonzero_false(self):
- """Test related to #13085"""
- # __nonzero__() returns False -- This actually doesn't currently fail.
- # This test validates that
+ def test_target_model_bool_false(self):
+ """
+ Saving a model with a GenericForeignKey to a model instance whose
+ __bool__ method returns False (Guild.__bool__() here) shouldn't fail
+ (#13085).
+ """
g1 = Guild.objects.create(name='First guild')
note = Note(note='Note for guild', content_object=g1)
note.save()