jenkins-bot merged this change.
[IMPR] Use a set as default container
A set is the the appropriate implemetation of a container holding all
seen items instead using a dict with it's key and unused value.
Don't care about 2 nanoseconds which is lower than the function overhead!
Change-Id: I7edc8205a017448a5a1ab51cce8c2c90174e48da
---
M pywikibot/tools/__init__.py
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index 6ef05c5..08677a9 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -843,14 +843,14 @@
"""
Yield unique items from an iterable, omitting duplicates.
- By default, to provide uniqueness, it puts the generated items into
- the keys of a dict created as a local variable, each with a value of True.
- It only yields items which are not already present in the local dict.
+ By default, to provide uniqueness, it puts the generated items into a
+ set created as a local variable. It only yields items which are not
+ already present in the local set.
For large collections, this is not memory efficient, as a strong reference
- to every item is kept in a local dict which can not be cleared.
+ to every item is kept in a local set which can not be cleared.
- Also, the local dict cant be re-used when chaining unique operations on
+ Also, the local set can't be re-used when chaining unique operations on
multiple generators.
To avoid these issues, it is advisable for the caller to provide their own
@@ -876,7 +876,7 @@
@type add: callable
"""
if container is None:
- container = {}
+ container = set()
if not add:
if hasattr(container, 'add'):
To view, visit change 433520. To unsubscribe, visit settings.