jenkins-bot submitted this change.

View Change

Approvals: Matěj Suchánek: Looks good to me, but someone else must approve Xqt: Looks good to me, approved jenkins-bot: Verified
[cleanup] Remove _get_baserevid and deprecated preloaditempages methods

The usage of baserevid is deprecated for 6 years.
preloaditempages() is deprecated for 4 years.

- replace _get_baserevid calls with claim.on_item.latest_revision_id
- use remove_last_args decorator to ignore baserevid parameter for
several methods
- use latest_revision_id of the only item in claims
- update typing and doc

Change-Id: I67736237d60c95d0db54556359836b8b43f42b74
---
M pywikibot/site/_datasite.py
1 file changed, 49 insertions(+), 83 deletions(-)

diff --git a/pywikibot/site/_datasite.py b/pywikibot/site/_datasite.py
index 0dbb3e5..1b4e827 100644
--- a/pywikibot/site/_datasite.py
+++ b/pywikibot/site/_datasite.py
@@ -23,12 +23,7 @@
)
from pywikibot.site._apisite import APISite
from pywikibot.site._decorators import need_right, need_version
-from pywikibot.tools import (
- deprecated,
- issue_deprecation_warning,
- itergroup,
- merge_unique_dicts,
-)
+from pywikibot.tools import itergroup, merge_unique_dicts, remove_last_args


__all__ = ('DataSite', )
@@ -141,29 +136,6 @@
"""
return self.siteinfo['general']['wikibase-conceptbaseuri']

- def _get_baserevid(self, claim, baserevid):
- """Check that claim.on_item is set and matches baserevid if used."""
- if not claim.on_item:
- issue_deprecation_warning('claim without on_item set', depth=3,
- since='20160309')
- if not baserevid:
- warn('Neither claim.on_item nor baserevid provided',
- UserWarning, 3)
- return baserevid
-
- if not baserevid:
- return claim.on_item.latest_revision_id
-
- issue_deprecation_warning(
- 'Site method with baserevid', 'claim with on_item set', depth=3,
- since='20150910')
- if baserevid != claim.on_item.latest_revision_id:
- warn('Using baserevid {} instead of claim baserevid {}'
- .format(baserevid, claim.on_item.latest_revision_id),
- UserWarning, 3)
-
- return baserevid
-
def geo_shape_repository(self):
"""Return Site object for the geo-shapes repository e.g. commons."""
url = self.siteinfo['general'].get('wikibase-geoshapestoragebaseurl')
@@ -249,11 +221,6 @@
page.get() # cannot provide get_redirect=True (T145971)
yield page

- @deprecated('DataSite.preload_entities', since='20170314')
- def preloaditempages(self, pagelist, groupsize=50):
- """DEPRECATED."""
- return self.preload_entities(pagelist, groupsize)
-
def getPropertyType(self, prop):
"""
Obtain the type of a property.
@@ -423,29 +390,28 @@
return data

@need_right('edit')
- def editSource(self, claim, source, new=False,
- bot=True, summary=None, baserevid=None):
- """
- Create/Edit a source.
+ @remove_last_args(['baserevid']) # since 7.0.0
+ def editSource(self, claim, source,
+ new: bool = False,
+ bot: bool = True,
+ summary: Optional[str] = None):
+ """Create/Edit a source.
+
+ .. versionchanged:: 7.0
+ deprecated `baserevid` parameter was removed

:param claim: A Claim object to add the source to
:type claim: pywikibot.Claim
:param source: A Claim object to be used as a source
:type source: pywikibot.Claim
:param new: Whether to create a new one if the "source" already exists
- :type new: bool
:param bot: Whether to mark the edit as a bot edit
- :type bot: bool
:param summary: Edit summary
- :type summary: str
- :param baserevid: Base revision id override, used to detect conflicts.
- When omitted, revision of claim.on_item is used. DEPRECATED.
- :type baserevid: long
"""
if claim.isReference or claim.isQualifier:
raise ValueError('The claim cannot have a source.')
params = {'action': 'wbsetreference', 'statement': claim.snak,
- 'baserevid': self._get_baserevid(claim, baserevid),
+ 'baserevid': claim.on_item.latest_revision_id,
'summary': summary, 'bot': bot, 'token': self.tokens['edit']}

# build up the snak
@@ -477,27 +443,29 @@
return req.submit()

@need_right('edit')
- def editQualifier(self, claim, qualifier, new=False, bot=True,
- summary=None, baserevid=None):
- """
- Create/Edit a qualifier.
+ @remove_last_args(['baserevid']) # since 7.0.0
+ def editQualifier(self, claim, qualifier,
+ new: bool = False,
+ bot: bool = True,
+ summary: Optional[str] = None):
+ """Create/Edit a qualifier.
+
+ .. versionchanged:: 7.0
+ deprecated `baserevid` parameter was removed

:param claim: A Claim object to add the qualifier to
:type claim: pywikibot.Claim
:param qualifier: A Claim object to be used as a qualifier
:type qualifier: pywikibot.Claim
+ :param new: Whether to create a new one if the "qualifier"
+ already exists
:param bot: Whether to mark the edit as a bot edit
- :type bot: bool
:param summary: Edit summary
- :type summary: str
- :param baserevid: Base revision id override, used to detect conflicts.
- When omitted, revision of claim.on_item is used. DEPRECATED.
- :type baserevid: long
"""
if claim.isReference or claim.isQualifier:
raise ValueError('The claim cannot have a qualifier.')
params = {'action': 'wbsetqualifier', 'claim': claim.snak,
- 'baserevid': self._get_baserevid(claim, baserevid),
+ 'baserevid': claim.on_item.latest_revision_id,
'summary': summary, 'bot': bot}

if (not new and hasattr(qualifier, 'hash')
@@ -514,9 +482,14 @@
return req.submit()

@need_right('edit')
- def removeClaims(self, claims, bot=True, summary=None, baserevid=None):
- """
- Remove claims.
+ @remove_last_args(['baserevid']) # since 7.0.0
+ def removeClaims(self, claims,
+ bot: bool = True,
+ summary: Optional[str] = None):
+ """Remove claims.
+
+ .. versionchanged:: 7.0
+ deprecated `baserevid` parameter was removed

:param claims: Claims to be removed
:type claims: List[pywikibot.Claim]
@@ -524,16 +497,11 @@
:type bot: bool
:param summary: Edit summary
:type summary: str
- :param baserevid: Base revision id override, used to detect conflicts.
- When omitted, revision of claim.on_item is used. DEPRECATED.
- :type baserevid: long
"""
- # Check on_item vs baserevid for all additional claims
- for claim in claims:
- baserevid = self._get_baserevid(claim, baserevid)
-
+ # Check on_item for all additional claims
items = {claim.on_item for claim in claims if claim.on_item}
assert len(items) == 1
+ baserevid = items.pop().latest_revision_id

params = {
'action': 'wbremoveclaims', 'baserevid': baserevid,
@@ -547,26 +515,25 @@
return req.submit()

@need_right('edit')
+ @remove_last_args(['baserevid']) # since 7.0.0
def removeSources(self, claim, sources,
- bot=True, summary=None, baserevid=None):
- """
- Remove sources.
+ bot: bool = True,
+ summary: Optional[str] = None):
+ """Remove sources.
+
+ .. versionchanged:: 7.0
+ deprecated `baserevid` parameter was removed

:param claim: A Claim object to remove the sources from
:type claim: pywikibot.Claim
:param sources: A list of Claim objects that are sources
:type sources: list
:param bot: Whether to mark the edit as a bot edit
- :type bot: bool
:param summary: Edit summary
- :type summary: str
- :param baserevid: Base revision id override, used to detect conflicts.
- When omitted, revision of claim.on_item is used. DEPRECATED.
- :type baserevid: long
"""
params = {
'action': 'wbremovereferences',
- 'baserevid': self._get_baserevid(claim, baserevid),
+ 'baserevid': claim.on_item.latest_revision_id,
'summary': summary, 'bot': bot,
'statement': claim.snak,
'references': '|'.join(source.hash for source in sources),
@@ -577,27 +544,26 @@
return req.submit()

@need_right('edit')
+ @remove_last_args(['baserevid']) # since 7.0.0
def remove_qualifiers(self, claim, qualifiers,
- bot=True, summary=None, baserevid=None):
- """
- Remove qualifiers.
+ bot: bool = True,
+ summary: Optional[str] = None):
+ """Remove qualifiers.
+
+ .. versionchanged:: 7.0
+ deprecated `baserevid` parameter was removed

:param claim: A Claim object to remove the qualifier from
:type claim: pywikibot.Claim
:param qualifiers: Claim objects currently used as a qualifiers
:type qualifiers: List[pywikibot.Claim]
:param bot: Whether to mark the edit as a bot edit
- :type bot: bool
:param summary: Edit summary
- :type summary: str
- :param baserevid: Base revision id override, used to detect conflicts.
- When omitted, revision of claim.on_item is used. DEPRECATED.
- :type baserevid: long
"""
params = {
'action': 'wbremovequalifiers',
'claim': claim.snak,
- 'baserevid': self._get_baserevid(claim, baserevid),
+ 'baserevid': claim.on_item.latest_revision_id,
'summary': summary,
'bot': bot,
'qualifiers': [qualifier.hash for qualifier in qualifiers],

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

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