Xqt has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1328305?usp=email )
Change subject: wikibase: Reuse claim target during formatting
......................................................................
wikibase: Reuse claim target during formatting
Resolve the claim target once before selecting its Wikibase serialization.
This avoids repeated accessor calls and keeps every formatting branch on
the same target value.
Change-Id: I2018efa03f72e70f9acf24778b1ddf6edcf9c33a
---
M pywikibot/page/_wikibase.py
1 file changed, 10 insertions(+), 8 deletions(-)
Approvals:
Xqt: Verified; Looks good to me, approved
diff --git a/pywikibot/page/_wikibase.py b/pywikibot/page/_wikibase.py
index 4403d57..6d165da 100644
--- a/pywikibot/page/_wikibase.py
+++ b/pywikibot/page/_wikibase.py
@@ -2198,27 +2198,29 @@
:return: JSON value
"""
+ target = self.getTarget()
+
# TODO: eventually unify the following two groups
if self.type in ('wikibase-item', 'wikibase-property'):
- value = {'entity-type': self.getTarget().entity_type,
- 'numeric-id': self.getTarget().getID(numeric=True)}
+ value = {'entity-type': target.entity_type,
+ 'numeric-id': target.getID(numeric=True)}
elif self.type in (
'wikibase-lexeme', 'wikibase-form', 'wikibase-sense'):
- value = {'entity-type': self.getTarget().entity_type,
- 'id': self.getTarget().getID()}
+ value = {'entity-type': target.entity_type,
+ 'id': target.getID()}
elif self.type in ('string', 'url', 'math', 'external-id',
'musical-notation'):
- value = self.getTarget()
+ value = target
elif self.type == 'commonsMedia':
- value = self.getTarget().title(with_ns=False)
+ value = target.title(with_ns=False)
elif self.type in ('globe-coordinate', 'time',
'quantity', 'monolingualtext',
'geo-shape', 'tabular-data'):
- value = self.getTarget().toWikibase()
+ value = target.toWikibase()
else: # WbUnknown
pywikibot.warning(
f'{self.type} datatype is not supported yet.')
- value = self.getTarget().toWikibase()
+ value = target.toWikibase()
return value
def _formatDataValue(self) -> dict:
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1328305?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: I2018efa03f72e70f9acf24778b1ddf6edcf9c33a
Gerrit-Change-Number: 1328305
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]