diff --git a/compose/utils.py b/compose/utils.py index b9b6ab9bd..72e6ced17 100644 --- a/compose/utils.py +++ b/compose/utils.py @@ -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 diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py index 186b6b14e..21b88d962 100644 --- a/tests/unit/utils_test.py +++ b/tests/unit/utils_test.py @@ -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]