Use dict.popitem when we know the dict only has one key

This commit is contained in:
Honza Král
2013-12-08 19:27:44 +01:00
parent e9eaefd999
commit 0ab904c4de
+2 -2
View File
@@ -1,4 +1,4 @@
from itertools import islice, chain
from itertools import islice
from operator import methodcaller
try:
from itertools import imap as map
@@ -106,7 +106,7 @@ def streaming_bulk(client, actions, chunk_size=500, raise_on_error=False, expand
resp = client.bulk(bulk_actions, **kwargs)
# go through request-reponse pairs and detect failures
for op_type, item in chain.from_iterable(map(methodcaller('items'), resp['items'])):
for op_type, item in map(methodcaller('popitem'), resp['items']):
ok = item.get('ok')
if not ok and raise_on_error:
errors.append({op_type: item})