1
0
mirror of https://github.com/django/django.git synced 2025-10-27 07:36:08 +00:00

Improved error message when index in __getitem__() is invalid.

This commit is contained in:
Jon Dufresne
2019-07-19 13:55:32 -07:00
committed by Mariusz Felisiak
parent 8323691de0
commit d89053585e
6 changed files with 28 additions and 4 deletions

View File

@@ -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):