jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[bugfix] Clean up DataSite._wbset_action

- Fix prepare_data for wbsetaliases:
-- Intersection of two sets will never be equal to an (empty) dict.
-- Make it not contradict the main docstring.
- Fix 'bot' argument: in Pywikibot, the default is True and there is
no reason to have it different here.
- Support WikibaseEntity.
- Support lazy-loading for pywikibot.Page as the definition.
- Support 'tags' as a keyword argument since it is already
supported by the API.
- Add @need_right.
- Clean up typos.

Change-Id: Ib0126fcfec322a46ad95612ed7db77b61ec97fde
---
M pywikibot/site/_datasite.py
1 file changed, 22 insertions(+), 18 deletions(-)

diff --git a/pywikibot/site/_datasite.py b/pywikibot/site/_datasite.py
index 8b271b3..56dd857 100644
--- a/pywikibot/site/_datasite.py
+++ b/pywikibot/site/_datasite.py
@@ -740,16 +740,17 @@
total=total, parameters=parameters)
return gen

+ @need_right('edit')
def _wbset_action(self, itemdef, action, action_data, **kwargs):
"""
- Execute wbset{action}' on a Wikibase entity.
+ Execute wbset{action} on a Wikibase entity.

Supported actions are:
wbsetaliases, wbsetdescription, wbsetlabel and wbsetsitelink

:param itemdef: Item to modify or create
- :type itemdef: str, WikibasePage or Page coonected to such item
- :param action: wbset{action] to perform:
+ :type itemdef: str, WikibaseEntity or Page connected to such item
+ :param action: wbset{action} to perform:
'wbsetaliases', 'wbsetdescription', 'wbsetlabel', 'wbsetsitelink'
:type action: str
:param data: data to be used in API request, see API help
@@ -767,8 +768,10 @@
wbsetsitelink:
dict shall have keys 'linksite', 'linktitle' and
optionally 'badges'
- @kwargs bot: Whether to mark the edit as a bot edit, default is False
+ @kwargs bot: Whether to mark the edit as a bot edit, default is True
:type bot: bool
+ @kwargs tags: Change tags to apply with the edit
+ :type tags: list of str
:return: query result
:rtype: dict
:raises AssertionError, TypeError
@@ -792,8 +795,10 @@
res = data
keys = set(res)
assert keys < {'language', 'add', 'remove', 'set'}
- assert keys & {'add', 'set'} == {}
- assert keys & {'remove', 'set'} == {}
+ assert 'language' in keys
+ assert ({'add', 'remove', 'set'} & keys)
+ assert not ({'add', 'set'} < keys)
+ assert not ({'remove', 'set'} < keys)
elif action in ('wbsetlabel', 'wbsetdescription'):
res = data
keys = set(res)
@@ -817,30 +822,29 @@
if isinstance(itemdef, str):
itemdef = self.get_entity_for_entity_id(itemdef)
elif isinstance(itemdef, pywikibot.Page):
- try:
- itemdef = itemdef.data_item()
- except NoPageError:
- itemdef = pywikibot.ItemPage(self)
- if not isinstance(itemdef, pywikibot.page.WikibasePage):
- raise TypeError('itemdef shall be str, WikibasePage or Page')
+ itemdef = pywikibot.ItemPage.fromPage(lazy_load=True)
+ elif not isinstance(itemdef, pywikibot.page.WikibaseEntity):
+ raise TypeError('itemdef shall be str, WikibaseEntity or Page')

params = itemdef._defined_by(singular=True)
# TODO: support 'new'
- baserevid = kwargs.pop('baserevid', 0) or itemdef.latest_revision_id
+ baserevid = kwargs.pop(
+ 'baserevid',
+ itemdef.latest_revision_id if 'id' in params else 0
+ )
params.update(
- {'id': itemdef.id,
- 'baserevid': baserevid,
+ {'baserevid': baserevid,
'action': action,
'token': self.tokens['edit'],
- 'bot': kwargs.pop('bot', False),
+ 'bot': kwargs.pop('bot', True),
})
params.update(prepare_data(action, action_data))

for arg in kwargs:
- if arg in ['summary']:
+ if arg in ['summary', 'tags']:
params[arg] = kwargs[arg]
else:
- warn('Unknown parameter {} for action {}, ignored'
+ warn('Unknown parameter {} for action {}, ignored'
.format(arg, action), UserWarning, 2)

req = self._simple_request(**params)

To view, visit change 698156. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ib0126fcfec322a46ad95612ed7db77b61ec97fde
Gerrit-Change-Number: 698156
Gerrit-PatchSet: 1
Gerrit-Owner: Matěj Suchánek <matejsuchanek97@gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged