1
0
mirror of https://github.com/django/django.git synced 2025-10-29 08:36:09 +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

@@ -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))), \