jenkins-bot merged this change.

View Change

Approvals: Zhuyifei1999: Looks good to me, but someone else must approve Framawiki: Looks good to me, approved jenkins-bot: Verified
[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.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I7edc8205a017448a5a1ab51cce8c2c90174e48da
Gerrit-Change-Number: 433520
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Framawiki <framawiki@tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb@gmail.com>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999@gmail.com>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444@gmail.com>
Gerrit-Reviewer: jenkins-bot <>