Xqt has submitted this change and it was merged.
Change subject: Use defaultdict for local source var in page.py
......................................................................
Use defaultdict for local source var in page.py
In functions:
-. referenceFromJSON()
-. addSources()
Change-Id: I020362199681887c05d6c800a69d7251794e7a71
---
M pywikibot/page.py
1 file changed, 5 insertions(+), 10 deletions(-)
Approvals:
Xqt: Verified; Looks good to me, approved
jenkins-bot: Checked
diff --git a/pywikibot/page.py b/pywikibot/page.py
index d9bc7ff..d40e3a5 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -21,6 +21,7 @@
import threading
import unicodedata
import urllib
+import collections
logger = logging.getLogger("pywiki.wiki.page")
@@ -2809,14 +2810,11 @@
bit differently, and require some
more handling.
"""
- source = {}
+ source = collections.defaultdict(list)
for prop in data['snaks'].values():
for claimsnak in prop:
claim = Claim.fromJSON(site, {'mainsnak': claimsnak,
'hash': data['hash']})
- if claim.getID() in source:
- source[claim.getID()].append(claim)
- else:
- source[claim.getID()] = [claim]
+ source[claim.getID()].append(claim)
return source
@staticmethod
@@ -2908,14 +2906,11 @@
@type claims: list of pywikibot.Claim
"""
data = self.repo.editSource(self, claims, new=True, **kwargs)
- source = {}
+ source = collections.defaultdict(list)
for claim in claims:
claim.hash = data['reference']['hash']
self.on_item.lastrevid = data['pageinfo']['lastrevid']
- if claim.getID() in source:
- source[claim.getID()].append(claim)
- else:
- source[claim.getID()] = [claim]
+ source[claim.getID()].append(claim)
self.sources.append(source)
def _formatDataValue(self):
--
To view, visit
https://gerrit.wikimedia.org/r/86257
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I020362199681887c05d6c800a69d7251794e7a71
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot