utils: Fix typo in unique_everseen.

Signed-off-by: Antony MECHIN <antony.mechin@docker.com>
This commit is contained in:
Antony MECHIN 2018-09-27 13:58:38 +02:00 committed by Silvin Lubecki
parent b64184e388
commit eb86881af1
2 changed files with 7 additions and 4 deletions

View File

@ -176,6 +176,7 @@ def unique_everseen(iterable, key=lambda x: x):
"List unique elements, preserving order. Remember all elements ever seen."
seen = set()
for element in iterable:
if key(element) not in seen:
seen.add(element)
unique_key = key(element)
if unique_key not in seen:
seen.add(unique_key)
yield element

View File

@ -72,5 +72,7 @@ class TestParseBytes(object):
class TestMoreItertools(object):
def test_unique_everseen(self):
assert list(utils.unique_everseen([2, 1, 2, 1])) == [2, 1]
assert list(utils.unique_everseen([2, 1, 2, 1], hash)) == [2, 1]
unique = utils.unique_everseen
assert list(unique([2, 1, 2, 1])) == [2, 1]
assert list(unique([2, 1, 2, 1], hash)) == [2, 1]
assert list(unique([2, 1, 2, 1], lambda x: 'key_%s' % x)) == [2, 1]