jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1340530?usp=email )
Change subject: Reuse source values when checking existing claims
......................................................................
Reuse source values when checking existing claims
Read the source claim ID and target once before scanning an existing
claim's reference groups. Reuse them for property lookup and snak
comparison instead of calling the getters repeatedly.
Keep the source checks guarded by the existing override and source
conditions, and retain any/all short-circuiting.
Change-Id: I7a64523d73eadb35c55c366108a207e456fd71ad
---
M pywikibot/bot.py
1 file changed, 13 insertions(+), 11 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index f6ad427..407aeef 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -2219,17 +2219,19 @@
# FIXME: the user may provide a better source, but we only
# assume it's the default one
- if ('s' not in exists_arg and sourceclaim
- and any(sourceclaim.getID() in ref
- and all(snak.target_equals(sourceclaim.getTarget())
- for snak in ref[sourceclaim.getID()])
- for ref in existing.sources)):
- logger_callback(
- f'Skipping {claim_id} because claim with the same source'
- ' already exists')
- _log("Append 's' to -exists argument to override this "
- 'behavior')
- break
+ if 's' not in exists_arg and sourceclaim:
+ source_id = sourceclaim.getID()
+ source_target = sourceclaim.getTarget()
+ if any(source_id in ref
+ and all(snak.target_equals(source_target)
+ for snak in ref[source_id])
+ for ref in existing.sources):
+ logger_callback(
+ f'Skipping {claim_id} because claim with the same'
+ ' source already exists')
+ _log("Append 's' to -exists argument to override this "
+ 'behavior')
+ break
else:
return self.user_add_claim(item, claim, source, **kwargs)
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1340530?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I7a64523d73eadb35c55c366108a207e456fd71ad
Gerrit-Change-Number: 1340530
Gerrit-PatchSet: 2
Gerrit-Owner: Mahveotm <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]