Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/setuptools/_itertools.py: 20%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from more_itertools import consume # noqa: F401
4# copied from jaraco.itertools 6.1
5def ensure_unique(iterable, key=lambda x: x):
6 """
7 Wrap an iterable to raise a ValueError if non-unique values are encountered.
9 >>> list(ensure_unique('abc'))
10 ['a', 'b', 'c']
11 >>> consume(ensure_unique('abca'))
12 Traceback (most recent call last):
13 ...
14 ValueError: Duplicate element 'a' encountered.
15 """
16 seen = set()
17 seen_add = seen.add
18 for element in iterable:
19 k = key(element)
20 if k in seen:
21 raise ValueError(f"Duplicate element {element!r} encountered.")
22 seen_add(k)
23 yield element