summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2019-07-19 13:55:32 -0700
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-07-23 20:12:08 +0200
commitd89053585e11e869efcc9debb1c311b47b5e20ea (patch)
tree94c606567d2611fb47914a59800af3d9ab2da6be /django
parent8323691de0ba120dbdc8055063574df2b0c0afa4 (diff)
Improved error message when index in __getitem__() is invalid.
Diffstat (limited to 'django')
-rw-r--r--django/core/paginator.py5
-rw-r--r--django/db/models/query.py5
-rw-r--r--django/forms/boundfield.py5
3 files changed, 12 insertions, 3 deletions
diff --git a/django/core/paginator.py b/django/core/paginator.py
index d484c31ed5..73dfcd679f 100644
--- a/django/core/paginator.py
+++ b/django/core/paginator.py
@@ -151,7 +151,10 @@ class Page(collections.abc.Sequence):
def __getitem__(self, index):
if not isinstance(index, (int, slice)):
- raise TypeError
+ raise TypeError(
+ 'Page indices must be integers or slices, not %s.'
+ % type(index).__name__
+ )
# The object_list is converted to a list so that if it was a QuerySet
# it won't be a database hit per __getitem__.
if not isinstance(self.object_list, list):
diff --git a/django/db/models/query.py b/django/db/models/query.py
index 1544beb613..a62947d9d0 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -283,7 +283,10 @@ class QuerySet:
def __getitem__(self, k):
"""Retrieve an item or slice from the set of results."""
if not isinstance(k, (int, slice)):
- raise TypeError
+ raise TypeError(
+ 'QuerySet indices must be integers or slices, not %s.'
+ % type(k).__name__
+ )
assert ((not isinstance(k, slice) and (k >= 0)) or
(isinstance(k, slice) and (k.start is None or k.start >= 0) and
(k.stop is None or k.stop >= 0))), \
diff --git a/django/forms/boundfield.py b/django/forms/boundfield.py
index 7f40fbbbb4..8832169021 100644
--- a/django/forms/boundfield.py
+++ b/django/forms/boundfield.py
@@ -63,7 +63,10 @@ class BoundField:
# Prevent unnecessary reevaluation when accessing BoundField's attrs
# from templates.
if not isinstance(idx, (int, slice)):
- raise TypeError
+ raise TypeError(
+ 'BoundField indices must be integers or slices, not %s.'
+ % type(idx).__name__
+ )
return self.subwidgets[idx]
@property