From 0ab904c4de5a092835bc68ed97b581e32f6babb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Honza=20Kr=C3=A1l?= Date: Sun, 8 Dec 2013 19:27:44 +0100 Subject: [PATCH] Use dict.popitem when we know the dict only has one key --- elasticsearch/helpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/elasticsearch/helpers.py b/elasticsearch/helpers.py index 94539f2d..f8ef2976 100644 --- a/elasticsearch/helpers.py +++ b/elasticsearch/helpers.py @@ -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})