jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/971617 )
Change subject: [doc] Add some version hints
......................................................................
[doc] Add some version hints
Change-Id: I257cf42b37fb76bd09727206b716bb2c5ae9a034
---
M pywikibot/data/sparql.py
M pywikibot/page/_wikibase.py
M pywikibot/pagegenerators/_factory.py
3 files changed, 43 insertions(+), 20 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/data/sparql.py b/pywikibot/data/sparql.py
index 3417e32..85627aa 100644
--- a/pywikibot/data/sparql.py
+++ b/pywikibot/data/sparql.py
@@ -4,6 +4,7 @@
#
# Distributed under the terms of the MIT license.
#
+from textwrap import fill
from typing import Optional
from urllib.parse import quote
@@ -135,10 +136,14 @@
return result
def query(self, query: str, headers: Optional[Dict[str, str]] = None):
- """
- Run SPARQL query and return parsed JSON result.
+ """Run SPARQL query and return parsed JSON result.
+
+ .. versionchanged:: 8.5
+ :exc:``exceptions.NoUsernameError` is raised if the response
+ looks like the user is not logged in.
:param query: Query text
+ :raises NoUsernameError: User not logged in
"""
if headers is None:
headers = DEFAULT_HEADERS
@@ -165,15 +170,15 @@
# not in case the response otherwise might have it in between
strcontent = self.last_response.content.decode()
if (strcontent.startswith('<!DOCTYPE html>')
- and 'https://commons-query.wikimedia.org' in url):
- if ('Special:UserLogin' in strcontent
- or 'Special:OAuth' in strcontent):
- message = ('You need to log in to Wikimedia Commons '
- 'and give OAUTH permission. '
- 'Open
https://commons-query.wikimedia.org '
- 'with browser to login and give permission.')
- raise NoUsernameError('User not logged in. ' + message)
-
+ and 'https://commons-query.wikimedia.org' in url
+ and ('Special:UserLogin' in strcontent
+ or 'Special:OAuth' in strcontent)):
+ raise NoUsernameError(fill(
+ 'User not logged in. You need to log in to Wikimedia '
+ 'Commons and give OAUTH permission. Open '
+ 'https://commons-query.wikimedia.org with browser to '
+ 'login and give permission.'
+ ))
return None
def ask(self, query: str,
diff --git a/pywikibot/page/_wikibase.py b/pywikibot/page/_wikibase.py
index 0b88472..e3da067 100644
--- a/pywikibot/page/_wikibase.py
+++ b/pywikibot/page/_wikibase.py
@@ -94,7 +94,7 @@
DATA_ATTRIBUTES: Dict[str, Any] = {}
- def __init__(self, repo, id_=None) -> None:
+ def __init__(self, repo, id_: Optional[str] = None) -> None:
"""
Initializer.
@@ -141,14 +141,14 @@
for key, cls in self.DATA_ATTRIBUTES.items():
setattr(self, key, cls.new_empty(self.repo))
- def _defined_by(self, singular: bool = False) -> dict:
+ def _defined_by(self, singular: bool = False) -> Dict[str, str]:
"""
Internal function to provide the API parameters to identify the entity.
An empty dict is returned if the entity has not been created yet.
:param singular: Whether the parameter names should use the singular
- form
+ form
:return: API parameters
"""
params = {}
@@ -159,7 +159,7 @@
params['ids'] = self.id
return params
- def getID(self, numeric: bool = False):
+ def getID(self, numeric: bool = False) -> Union[int, str]:
"""
Get the identifier of this entity.
@@ -406,6 +406,8 @@
"""
Internal function to provide the API parameters to identify the entity.
+ .. versionadded:: 8.5
+
:param singular: Whether the parameter names should use the singular
form
:raise NoWikibaseEntityError: if this entity is associated with
@@ -500,13 +502,16 @@
>> page = pywikibot.FilePage(repo,
'File:Sandbox-Test.svg')
>> item = page.data_item()
>> item.editLabels({'en': 'Test file.'}) # doctest: +SKIP
+
+ .. versionadded:: 8.5
"""
data = {'labels': labels}
self.editEntity(data, **kwargs)
def addClaim(self, claim, bot: bool = True, **kwargs):
- """
- Add a claim to the MediaInfo.
+ """Add a claim to the MediaInfo.
+
+ .. versionadded:: 8.5
:param claim: The claim to add
:type claim: pywikibot.page.Claim
@@ -525,8 +530,9 @@
claim.on_item = self
def removeClaims(self, claims, **kwargs) -> None:
- """
- Remove the claims from the MediaInfo.
+ """Remove the claims from the MediaInfo.
+
+ .. versionadded:: 8.5
:param claims: list of claims to be removed
:type claims: list or pywikibot.Claim
diff --git a/pywikibot/pagegenerators/_factory.py b/pywikibot/pagegenerators/_factory.py
index 4a19361..6c26176 100644
--- a/pywikibot/pagegenerators/_factory.py
+++ b/pywikibot/pagegenerators/_factory.py
@@ -913,7 +913,10 @@
return self._parse_log_events(*params)
def _handle_redirect(self, value: str) -> HANDLER_RETURN_TYPE:
- """Handle `-redirect` argument."""
+ """Handle `-redirect` argument.
+
+ .. versionadded:: 8.5
+ """
if not value:
# True by default
value = 'true'
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/971617
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I257cf42b37fb76bd09727206b716bb2c5ae9a034
Gerrit-Change-Number: 971617
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged