mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Avoided creating temporary lists for obtaining the first item.
This commit is contained in:
committed by
Tim Graham
parent
0f905e4b44
commit
aadd3aeb2b
@@ -95,7 +95,7 @@ class ErrorList(UserList, list):
|
||||
def get_json_data(self, escape_html=False):
|
||||
errors = []
|
||||
for error in self.as_data():
|
||||
message = list(error)[0]
|
||||
message = next(iter(error))
|
||||
errors.append({
|
||||
'message': escape(message) if escape_html else message,
|
||||
'code': error.code or '',
|
||||
@@ -133,7 +133,7 @@ class ErrorList(UserList, list):
|
||||
def __getitem__(self, i):
|
||||
error = self.data[i]
|
||||
if isinstance(error, ValidationError):
|
||||
return list(error)[0]
|
||||
return next(iter(error))
|
||||
return error
|
||||
|
||||
def __reduce_ex__(self, *args, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user