jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/635380 )
Change subject: [IMPR] Replaced basestring by str
......................................................................
[IMPR] Replaced basestring by str
Bug: T265128
Change-Id: I20444cde3e5e857935b3dd35ca6ca13845cad455
---
M pywikibot/bot.py
M pywikibot/page/__init__.py
M pywikibot/proofreadpage.py
M pywikibot/site/__init__.py
M pywikibot/tools/__init__.py
M tests/api_tests.py
6 files changed, 105 insertions(+), 164 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 2abb868..746be8e 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -99,7 +99,7 @@
from importlib import import_module
from pathlib import Path
from textwrap import fill
-from typing import Any, Dict
+from typing import Any, Dict, Optional, Union
from warnings import warn
import pywikibot
@@ -427,20 +427,16 @@
# User input functions
-def input(question, password=False, default='', force=False):
+def input(question: str, password: bool = False,
+ default: str = '', force: bool = False) -> str:
"""Ask the user a question, return the user's answer.
@param question: a string that will be shown to the user. Don't add a
space after the question mark/colon, this method will do this for you.
- @type question: str
@param password: if True, hides the user's input (for password entry).
- @type password: bool
@param default: The default answer if none was entered. None to require
an answer.
- @type default: basestring
@param force: Automatically use the default
- @type force: bool
- @rtype: str
"""
# make sure logging system has been initialized
if not _handlers_initialized:
@@ -450,13 +446,13 @@
return data
-def input_choice(question, answers, default=None, return_shortcut=True,
- automatic_quit=True, force=False):
+def input_choice(question: str, answers, default: Optional[str] = None,
+ return_shortcut: bool = True,
+ automatic_quit: bool = True, force: bool = False):
"""
Ask the user the question and return one of the valid answers.
@param question: The question asked without trailing spaces.
- @type question: basestring
@param answers: The valid answers each containing a full length answer and
a shortcut. Each value must be unique.
@type answers: iterable containing a sequence of length two or instances of
@@ -464,19 +460,15 @@
@param default: The result if no answer was entered. It must not be in the
valid answers and can be disabled by setting it to None. If it should
be linked with the valid answers it must be its shortcut.
- @type default: basestring
@param return_shortcut: Whether the shortcut or the index of the answer is
returned.
- @type return_shortcut: bool
@param automatic_quit: Adds the option 'Quit' ('q') and throw a
L{QuitKeyboardInterrupt} if selected.
- @type automatic_quit: bool
@param force: Automatically use the default
- @type force: bool
@return: The selected answer shortcut or index. Is -1 if the default is
selected, it does not return the shortcut and the default is not a
valid shortcut.
- @rtype: int (if not return shortcut), basestring (otherwise)
+ @rtype: int (if not return shortcut), str (otherwise)
"""
# make sure logging system has been initialized
if not _handlers_initialized:
@@ -486,24 +478,22 @@
automatic_quit=automatic_quit, force=force)
-def input_yn(question, default=None, automatic_quit=True, force=False):
+def input_yn(question: str,
+ default: Union[str, bool, None] = None,
+ automatic_quit: bool = True,
+ force: bool = False) -> bool:
"""
Ask the user a yes/no question and return the answer as a bool.
@param question: The question asked without trailing spaces.
- @type question: basestring
@param default: The result if no answer was entered. It must be a bool or
'y' or 'n' and can be disabled by setting it to None.
- @type default: basestring or bool
@param automatic_quit: Adds the option 'Quit' ('q') and throw a
L{QuitKeyboardInterrupt} if selected.
- @type automatic_quit: bool
@param force: Automatically use the default
- @type force: bool
@return: Return True if the user selected yes and False if the user
selected no. If the default is not None it'll return True if default
is True or 'y' and False if default is False or 'n'.
- @rtype: bool
"""
if default not in ['y', 'Y', 'n', 'N']:
if default:
@@ -517,21 +507,19 @@
automatic_quit=automatic_quit, force=force) == 'y'
-def input_list_choice(question, answers, default=None, force=False):
+def input_list_choice(question: str, answers,
+ default: Optional[str] = None,
+ force: bool = False) -> str:
"""
Ask the user the question and return one of the valid answers.
@param question: The question asked without trailing spaces.
- @type question: basestring
@param answers: The valid answers each containing a full length answer.
- @type answers: Iterable of basestring
+ @type answers: Iterable of str
@param default: The result if no answer was entered. It must not be in the
valid answers and can be disabled by setting it to None.
- @type default: basestring
@param force: Automatically use the default
- @type force: bool
@return: The selected answer.
- @rtype: basestring
"""
if not _handlers_initialized:
init_handlers()
@@ -565,7 +553,8 @@
the Choice instance returned and created by this class are too.
"""
- def __init__(self, old_link, new_link, default=None, automatic_quit=True):
+ def __init__(self, old_link, new_link, default: Optional[str] = None,
+ automatic_quit: bool = True):
"""
Initializer.
@@ -578,10 +567,8 @@
with allow_replace are ignored.
@type new_link: pywikibot.page.Link or pywikibot.page.Page or False
@param default: The default answer as the shortcut
- @type default: None or str
@param automatic_quit: Add an option to quit and raise a
QuitKeyboardException.
- @type automatic_quit: bool
"""
if isinstance(old_link, pywikibot.Page):
self._old = old_link._link
@@ -722,13 +709,12 @@
# Command line parsing and help
-def calledModuleName():
+def calledModuleName() -> str:
"""Return the name of the module calling this function.
This is required because the -help option loads the module's docstring
and because the module name will be used for the filename of the log.
- @rtype: str
"""
return Path(pywikibot.argvu[0]).stem
@@ -912,8 +898,8 @@
def suggest_help(missing_parameters=[], missing_generator=False,
unknown_parameters=[], exception=None,
- missing_action=False, additional_text='',
- missing_dependencies=[]):
+ missing_action=False, additional_text: str = '',
+ missing_dependencies=[]) -> bool:
"""
Output error message to use -help with additional text before it.
@@ -928,12 +914,10 @@
@param missing_action: Add an entry that no action was defined.
@type missing_action: bool
@param additional_text: Additional text added to the end.
- @type additional_text: str
@param missing_dependencies: A list of dependencies which can not
be imported.
@type missing_dependencies: list of str
@return: True if an error message was printed, False otherwise
- @rtype: bool
"""
messages = []
if exception:
@@ -1777,15 +1761,14 @@
self.treat_page()
@deprecated_args(comment='summary')
- def put_current(self, new_text, ignore_save_related_errors=None,
- ignore_server_errors=None, **kwargs):
+ def put_current(self, new_text: str, ignore_save_related_errors=None,
+ ignore_server_errors=None, **kwargs) -> bool:
"""
Call L{Bot.userPut} but use the current page.
It compares the new_text to the current page text.
@param new_text: The new text
- @type new_text: basestring
@param ignore_save_related_errors: Ignore save related errors and
automatically print a message. If None uses this instances default.
@type ignore_save_related_errors: bool or None
@@ -1794,7 +1777,6 @@
@type ignore_server_errors: bool or None
@param kwargs: Additional parameters directly given to L{Bot.userPut}.
@return: whether the page was saved successfully
- @rtype: bool
"""
if ignore_save_related_errors is None:
ignore_save_related_errors = self.ignore_save_related_errors
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index 7e27dfd..a528733 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -615,12 +615,11 @@
return ''
@text.setter
- def text(self, value):
+ def text(self, value: str):
"""
Update the current (edited) wikitext.
@param value: New value or None
- @type value: basestring
"""
del self.text
self._text = None if value is None else str(value)
@@ -1957,7 +1956,6 @@
pg.undelete('This will restore only selected revisions.')
@param reason: Reason for the action.
- @type reason: basestring
"""
if hasattr(self, '_deletedRevs'):
undelete_revs = [ts for ts, rev in self._deletedRevs.items()
@@ -3217,12 +3215,11 @@
else:
raise err
- def unblock(self, reason=None):
+ def unblock(self, reason: Optional[str] = None):
"""
Remove the block for the user.
@param reason: Reason for the unblock.
- @type reason: basestring
"""
self.site.unblockuser(self, reason)
@@ -3231,9 +3228,9 @@
@keyword logtype: only iterate entries of this type
(see mediawiki api documentation for available types)
- @type logtype: basestring
+ @type logtype: str
@keyword page: only iterate entries affecting this page
- @type page: Page or basestring
+ @type page: Page or str
@keyword namespace: namespace to retrieve logevents from
@type namespace: int or Namespace
@keyword start: only iterate entries from and after this Timestamp
@@ -3244,7 +3241,7 @@
(default: newest)
@type reverse: bool
@keyword tag: only iterate entries tagged with this tag
- @type tag: basestring
+ @type tag: str
@keyword total: maximum number of events to iterate
@type total: int
@rtype: iterable
@@ -3261,7 +3258,7 @@
return next(iter(self.logevents(total=1)), None)
@deprecated_args(limit='total', namespace='namespaces')
- def contributions(self, total=500, **kwargs) -> tuple:
+ def contributions(self, total: int = 500, **kwargs) -> tuple:
"""
Yield tuples describing this user edits.
@@ -3271,12 +3268,11 @@
Pages returned are not guaranteed to be unique.
@param total: limit result to this number of pages
- @type total: int
@keyword start: Iterate contributions starting at this Timestamp
@keyword end: Iterate contributions ending at this Timestamp
@keyword reverse: Iterate oldest contributions first (default: newest)
@keyword namespaces: only iterate pages in these namespaces
- @type namespaces: iterable of basestring or Namespace key,
+ @type namespaces: iterable of str or Namespace key,
or a single instance of those types. May be a '|' separated
list of namespace identifiers.
@keyword showMinor: if True, iterate only minor edits; if False and
@@ -4544,16 +4540,14 @@
return page._item
@classmethod
- def from_entity_uri(cls, site, uri, lazy_load=False):
+ def from_entity_uri(cls, site, uri: str, lazy_load: bool = False):
"""
Get the ItemPage from its entity uri.
@param site: The Wikibase site for the item.
@type site: pywikibot.site.DataSite
@param uri: Entity uri for the Wikibase item.
- @type uri: basestring
@param lazy_load: Do not raise NoPage if ItemPage does not exist.
- @type lazy_load: bool
@rtype: pywikibot.page.ItemPage
@raise TypeError: Site is not a valid DataSite.
@@ -4787,17 +4781,15 @@
'tabular-data': 'string',
}
- def __init__(self, site, id, datatype=None):
+ def __init__(self, site, id: str, datatype: Optional[str] = None):
"""
Initializer.
@param site: data repository
@type site: pywikibot.site.DataSite
@param id: id of the property
- @type id: basestring
@param datatype: datatype of the property;
if not given, it will be queried via the API
- @type datatype: basestring
"""
self.repo = site
self.id = id.upper()
diff --git a/pywikibot/proofreadpage.py b/pywikibot/proofreadpage.py
index e878859..b635abc 100644
--- a/pywikibot/proofreadpage.py
+++ b/pywikibot/proofreadpage.py
@@ -701,7 +701,7 @@
return self._ocr_callback(cmd_uri, ocr_tool=ocr_tool)
- def ocr(self, ocr_tool=None):
+ def ocr(self, ocr_tool: Optional[str] = None):
"""Do OCR of ProofreadPage scan.
The text returned by this function shall be assigned to self.body,
@@ -710,7 +710,6 @@
It is the user's responsibility to reset quality level accordingly.
@param ocr_tool: 'phetools' or 'googleOCR', default is 'phetools'
- @type ocr_tool: basestring
@return: OCR text for the page.
diff --git a/pywikibot/site/__init__.py b/pywikibot/site/__init__.py
index a4271c6..f4408a1 100644
--- a/pywikibot/site/__init__.py
+++ b/pywikibot/site/__init__.py
@@ -213,15 +213,13 @@
"""
return name in (x.lower() for x in self._distinct())
- def __contains__(self, item):
+ def __contains__(self, item: str) -> bool:
"""Determine if item is a name of this namespace.
The comparison is case insensitive, and item may have a single
colon on one or both sides of the name.
@param item: name to check
- @type item: basestring
- @rtype: bool
"""
if item == '' and self.id == 0:
return True
@@ -388,12 +386,11 @@
@classmethod
@deprecated('NamespacesDict.lookup_name', since='20150703',
future_warning=True)
- def lookup_name(cls, name, namespaces=None):
+ def lookup_name(cls, name: str, namespaces=None):
"""
Find the Namespace for a name.
@param name: Name of the namespace.
- @type name: basestring
@param namespaces: namespaces to search
default: builtins only
@type namespaces: dict of Namespace
@@ -416,7 +413,7 @@
successfully finds. A numerical string is resolved as an integer.
@param identifiers: namespace identifiers
- @type identifiers: iterable of basestring or Namespace key,
+ @type identifiers: iterable of str or Namespace key,
or a single instance of those types
@param namespaces: namespaces to search (default: builtins only)
@type namespaces: dict of Namespace
@@ -497,12 +494,11 @@
"""Get the number of namespaces."""
return len(self._namespaces)
- def lookup_name(self, name):
+ def lookup_name(self, name: str):
"""
Find the Namespace for a name also checking aliases.
@param name: Name of the namespace.
- @type name: basestring
@rtype: Namespace or None
"""
name = Namespace.normalize_name(name)
@@ -510,14 +506,13 @@
return None
return self.lookup_normalized_name(name.lower())
- def lookup_normalized_name(self, name):
+ def lookup_normalized_name(self, name: str):
"""
Find the Namespace for a name also checking aliases.
The name has to be normalized and must be lower case.
@param name: Name of the namespace.
- @type name: basestring
@rtype: Namespace or None
"""
return self._namespace_names.get(name)
@@ -545,7 +540,7 @@
successfully finds. A numerical string is resolved as an integer.
@param identifiers: namespace identifiers
- @type identifiers: iterable of basestring or Namespace key,
+ @type identifiers: iterable of str or Namespace key,
or a single instance of those types
@return: list of Namespace objects in the same order as the
identifiers
@@ -1361,7 +1356,7 @@
constructor unchanged (not all types require this)
@param namespaces: if not None, limit the query to namespaces in
this list
- @type namespaces: iterable of basestring or Namespace key,
+ @type namespaces: iterable of str or Namespace key,
or a single instance of those types. May be a '|' separated
list of namespace identifiers.
@param total: if not None, limit the generator to yielding this
@@ -2988,7 +2983,7 @@
both (no filtering).
@param namespaces: If present, only return links from the namespaces
in this list.
- @type namespaces: iterable of basestring or Namespace key,
+ @type namespaces: iterable of str or Namespace key,
or a single instance of those types. May be a '|' separated
list of namespace identifiers.
@param total: Maximum number of pages to retrieve in total.
@@ -3049,7 +3044,7 @@
None, return both (no filtering).
@param namespaces: If present, only return links from the namespaces
in this list.
- @type namespaces: iterable of basestring or Namespace key,
+ @type namespaces: iterable of str or Namespace key,
or a single instance of those types. May be a '|' separated
list of namespace identifiers.
@param content: if True, load the current content of each iterated page
@@ -3082,7 +3077,7 @@
@param namespaces: If present, only return links from the namespaces
in this list.
- @type namespaces: iterable of basestring or Namespace key,
+ @type namespaces: iterable of str or Namespace key,
or a single instance of those types. May be a '|' separated
list of namespace identifiers.
@rtype: typing.Iterable[pywikibot.Page]
@@ -3120,7 +3115,7 @@
@param namespaces: Only iterate pages in these namespaces
(default: all)
- @type namespaces: iterable of basestring or Namespace key,
+ @type namespaces: iterable of str or Namespace key,
or a single instance of those types. May be a '|' separated
list of namespace identifiers.
@param follow_redirects: if True, yields the target of any redirects,
@@ -3187,7 +3182,7 @@
@see: U{https://www.mediawiki.org/wiki/API:Templates}
@param namespaces: Only iterate pages in these namespaces
- @type namespaces: iterable of basestring or Namespace key,
+ @type namespaces: iterable of str or Namespace key,
or a single instance of those types. May be a '|' separated
list of namespace identifiers.
@param content: if True, load the current content of each iterated page
@@ -3216,7 +3211,7 @@
@param namespaces: If present, only return category members from
these namespaces. To yield subcategories or files, use
parameter member_type instead.
- @type namespaces: iterable of basestring or Namespace key,
+ @type namespaces: iterable of str or Namespace key,
or a single instance of those types. May be a '|' separated
list of namespace identifiers.
@param sortby: determines the order in which results are generated,
@@ -3832,7 +3827,8 @@
@deprecated_args(step=None)
def blocks(self, starttime=None, endtime=None, reverse=False,
- blockids=None, users=None, iprange=None, total=None):
+ blockids=None, users=None, iprange: Optional[str] = None,
+ total: Optional[int] = None):
"""Iterate all current blocks, in order of creation.
The iterator yields dicts containing keys corresponding to the
@@ -3851,15 +3847,13 @@
@param reverse: if True, iterate oldest blocks first (default: newest)
@type reverse: bool
@param blockids: only iterate blocks with these id numbers. Numbers
- must be separated by '|' if given by a basestring.
- @type blockids: basestring, tuple or list
+ must be separated by '|' if given by a str.
+ @type blockids: str, tuple or list
@param users: only iterate blocks affecting these usernames or IPs
- @type users: basestring, tuple or list
+ @type users: str, tuple or list
@param iprange: a single IP or an IP range. Ranges broader than
IPv4/16 or IPv6/19 are not accepted.
- @type iprange: str
@param total: total amount of block entries
- @type total: int
"""
if starttime and endtime:
self.assert_valid_iter_params('blocks', starttime, endtime,
@@ -3889,8 +3883,9 @@
return bkgen
@deprecated_args(step=None)
- def exturlusage(self, url=None, protocol=None, namespaces=None,
- total=None, content=False):
+ def exturlusage(self, url: Optional[str] = None,
+ protocol: Optional[str] = None, namespaces=None,
+ total: Optional[int] = None, content=False):
"""Iterate Pages that contain links to the given URL.
@see: U{https://www.mediawiki.org/wiki/API:Exturlusage}
@@ -3898,14 +3893,11 @@
@param url: The URL to search for (with ot without the protocol
prefix); this may include a '*' as a wildcard, only at the start
of the hostname
- @type url: str
@param namespaces: list of namespace numbers to fetch contribs from
@type namespaces: list of int
@param total: Maximum number of pages to retrieve in total
- @type total: int
@param protocol: Protocol to search for, likely http or https, http by
default. Full list shown on Special:LinkSearch wikipage
- @type protocol: str
"""
separator = '://'
if separator in url:
@@ -3938,7 +3930,7 @@
the wiki)
@type image: pywikibot.FilePage
@param namespaces: If present, only iterate pages in these namespaces
- @type namespaces: iterable of basestring or Namespace key,
+ @type namespaces: iterable of str or Namespace key,
or a single instance of those types. May be a '|' separated
list of namespace identifiers.
@param filterredir: if True, only yield redirects; if False (and not
@@ -3964,8 +3956,11 @@
'query+logevents', 'type')['type']))
@deprecated_args(step=None)
- def logevents(self, logtype=None, user=None, page=None, namespace=None,
- start=None, end=None, reverse=False, tag=None, total=None):
+ def logevents(self, logtype: Optional[str] = None,
+ user: Optional[str] = None, page=None,
+ namespace=None, start=None, end=None,
+ reverse: bool = False, tag: Optional[str] = None,
+ total: Optional[int] = None):
"""Iterate all log entries.
@see: U{https://www.mediawiki.org/wiki/API:Logevents}
@@ -3975,9 +3970,7 @@
@param logtype: only iterate entries of this type
(see mediawiki api documentation for available types)
- @type logtype: basestring
@param user: only iterate entries that match this user name
- @type user: basestring
@param page: only iterate entries affecting this page
@type page: pywikibot.Page or str
@param namespace: namespace(s) to retrieve logevents from
@@ -3990,11 +3983,8 @@
@param end: only iterate entries up to and through this Timestamp
@type end: Timestamp or ISO date string
@param reverse: if True, iterate oldest entries first (default: newest)
- @type reverse: bool
@param tag: only iterate entries tagged with this tag
- @type tag: basestring
@param total: maximum number of events to iterate
- @type total: int
@rtype: iterable
@raises KeyError: the namespace identifier was not resolved
@@ -4059,7 +4049,7 @@
@type end: pywikibot.Timestamp
@param reverse: if True, start with oldest changes (default: newest)
@param namespaces: only iterate pages in these namespaces
- @type namespaces: iterable of basestring or Namespace key,
+ @type namespaces: iterable of str or Namespace key,
or a single instance of those types. May be a '|' separated
list of namespace identifiers.
@param changetype: only iterate changes of this type ("edit" for
@@ -4122,7 +4112,7 @@
@deprecated_args(number='total', step=None, key='searchstring',
getredirects='get_redirects')
- def search(self, searchstring, namespaces=None, where='text',
+ def search(self, searchstring: str, namespaces=None, where='text',
get_redirects=False, total=None, content=False):
"""Iterate Pages that contain the searchstring.
@@ -4132,11 +4122,10 @@
@see: U{https://www.mediawiki.org/wiki/API:Search}
@param searchstring: the text to search for
- @type searchstring: str
@param where: Where to search; value must be "text", "title" or
"nearmatch" (many wikis do not support title or nearmatch search)
@param namespaces: search only in these namespaces (defaults to all)
- @type namespaces: iterable of basestring or Namespace key,
+ @type namespaces: iterable of str or Namespace key,
or a single instance of those types. May be a '|' separated
list of namespace identifiers.
@param get_redirects: if True, include redirects in results. Since
@@ -4180,7 +4169,7 @@
@deprecated_args(step=None, showMinor='minor')
def usercontribs(self, user=None, userprefix=None, start=None, end=None,
reverse=False, namespaces=None, minor=None,
- total=None, top_only=False):
+ total: Optional[int] = None, top_only=False):
"""Iterate contributions by a particular user.
Iterated values are in the same format as recentchanges.
@@ -4194,13 +4183,12 @@
@param end: Iterate contributions ending at this Timestamp
@param reverse: Iterate oldest contributions first (default: newest)
@param namespaces: only iterate pages in these namespaces
- @type namespaces: iterable of basestring or Namespace key,
+ @type namespaces: iterable of str or Namespace key,
or a single instance of those types. May be a '|' separated
list of namespace identifiers.
@param minor: if True, iterate only minor edits; if False and
not None, iterate only non-minor edits (default: iterate both)
@param total: limit result to this number of pages
- @type total: int
@param top_only: if True, iterate only edits which are the latest
revision (default: False)
@raises pywikibot.exceptions.Error: either user or userprefix must be
@@ -4250,7 +4238,7 @@
@param end: Iterate revisions ending at this Timestamp
@param reverse: Iterate oldest revisions first (default: newest)
@param namespaces: only iterate pages in these namespaces
- @type namespaces: iterable of basestring or Namespace key,
+ @type namespaces: iterable of str or Namespace key,
or a single instance of those types. May be a '|' separated
list of namespace identifiers.
@param minor: if True, only list minor edits; if False (and not
@@ -4285,7 +4273,8 @@
@deprecated_args(step=None, get_text='content', page='titles',
limit='total')
- def deletedrevs(self, titles=None, start=None, end=None, reverse=False,
+ def deletedrevs(self, titles=None, start=None, end=None,
+ reverse: bool = False,
content=False, total=None, **kwargs):
"""Iterate deleted revisions.
@@ -4309,7 +4298,6 @@
@param start: Iterate revisions starting at this Timestamp
@param end: Iterate revisions ending at this Timestamp
@param reverse: Iterate oldest revisions first (default: newest)
- @type reverse: bool
@param content: If True, retrieve the content of each revision
@param total: number of revisions to retrieve
@keyword user: List revisions by this user
@@ -4427,7 +4415,7 @@
@param total: the maximum number of pages to iterate
@param namespaces: only iterate pages in these namespaces.
- @type namespaces: iterable of basestring or Namespace key,
+ @type namespaces: iterable of str or Namespace key,
or a single instance of those types. May be a '|' separated
list of namespace identifiers.
@param redirects: if True, include only redirect pages in results,
@@ -4497,7 +4485,7 @@
@need_right('edit')
def editpage(self, page, summary=None, minor=True, notminor=False,
bot=True, recreate=True, createonly=False, nocreate=False,
- watch=None, **kwargs):
+ watch=None, **kwargs) -> bool:
"""Submit an edit to be saved to the wiki.
@see: U{https://www.mediawiki.org/wiki/API:Edit}
@@ -4533,7 +4521,6 @@
@kwarg undo: Revision id to undo. Overrides Page.text
@type undo: int
@return: True if edit succeeded, False if it failed
- @rtype: bool
@raises pywikibot.exceptions.Error: No text to be saved
@raises pywikibot.exceptions.NoPage: recreate is disabled and page does
not exist
@@ -4717,7 +4704,8 @@
@need_right('mergehistory')
@need_version('1.27.0-wmf.13')
- def merge_history(self, source, dest, timestamp=None, reason=None):
+ def merge_history(self, source, dest, timestamp=None,
+ reason: Optional[str] = None):
"""Merge revisions from one page into another.
@see: U{https://www.mediawiki.org/wiki/API:Mergehistory}
@@ -4736,7 +4724,6 @@
all revisions will be merged)
@type timestamp: pywikibot.Timestamp
@param reason: Optional reason for the history merge
- @type reason: str
"""
# Data for error messages
errdata = {
@@ -4830,7 +4817,7 @@
}
@need_right('move')
- def movepage(self, page, newtitle, summary, movetalk=True,
+ def movepage(self, page, newtitle: str, summary, movetalk=True,
noredirect=False):
"""Move a Page to a new title.
@@ -4838,7 +4825,6 @@
@param page: the Page to be moved (must exist)
@param newtitle: the new title for the Page
- @type newtitle: str
@param summary: edit summary (required!)
@param movetalk: if True (default), also move the talk page if possible
@param noredirect: if True, suppress creation of a redirect from the
@@ -4999,7 +4985,7 @@
@need_right('delete')
@deprecate_arg('summary', 'reason')
- def deletepage(self, page, reason):
+ def deletepage(self, page, reason: str):
"""Delete page from the wiki. Requires appropriate privilege level.
@see: U{https://www.mediawiki.org/wiki/API:Delete}
@@ -5007,7 +4993,6 @@
@param page: Page to be deleted.
@type page: pywikibot.Page
@param reason: Deletion reason.
- @type reason: str
"""
token = self.tokens['delete']
@@ -5037,7 +5022,7 @@
@need_right('undelete')
@deprecate_arg('summary', 'reason')
- def undelete_page(self, page, reason, revisions=None):
+ def undelete_page(self, page, reason: str, revisions=None):
"""Undelete page from the wiki. Requires appropriate privilege level.
@see: U{https://www.mediawiki.org/wiki/API:Undelete}
@@ -5048,7 +5033,6 @@
If None, restores all revisions.
@type revisions: list
@param reason: Undeletion reason.
- @type reason: basestring
"""
token = self.tokens['delete']
@@ -5110,7 +5094,8 @@
@need_right('protect')
@deprecate_arg('summary', 'reason')
- def protect(self, page, protections, reason, expiry=None, **kwargs):
+ def protect(self, page, protections: dict,
+ reason: str, expiry=None, **kwargs):
"""(Un)protect a wiki page. Requires administrator status.
@see: U{https://www.mediawiki.org/wiki/API:Protect}
@@ -5120,9 +5105,7 @@
'move' and 'upload'. Valid restriction levels are '' (equivalent
to 'none' or 'all'), 'autoconfirmed', and 'sysop'.
If None is given, however, that protection will be skipped.
- @type protections: dict
@param reason: Reason for the action
- @type reason: basestring
@param expiry: When the block should expire. This expiry will be
applied to all protections. If None, 'infinite', 'indefinite',
'never', or '' is given, there is no expiry.
@@ -5267,9 +5250,9 @@
yield result['patrol']
@need_right('block')
- def blockuser(self, user, expiry, reason, anononly=True, nocreate=True,
- autoblock=True, noemail=False, reblock=False,
- allowusertalk=False):
+ def blockuser(self, user, expiry, reason: str, anononly=True,
+ nocreate=True, autoblock=True, noemail=False,
+ reblock=False, allowusertalk=False):
"""
Block a user for certain amount of time and for a certain reason.
@@ -5279,7 +5262,7 @@
@type user: L{pywikibot.User}
@param expiry: The length or date/time when the block expires. If
'never', 'infinite', 'indefinite' it never does. If the value is
- given as a basestring it's parsed by php's strtotime function:
+ given as a str it's parsed by php's strtotime function:
U{http://php.net/manual/en/function.strtotime.php}
@@ -5287,12 +5270,11 @@
U{http://php.net/manual/en/datetime.formats.relative.php}
- It is recommended to not use a basestring if possible to be
+ It is recommended to not use a str if possible to be
independent of the API.
@type expiry: Timestamp/datetime (absolute),
- basestring (relative/absolute) or False ('never')
+ str (relative/absolute) or False ('never')
@param reason: The reason for the block.
- @type reason: basestring
@param anononly: Disable anonymous edits for this IP.
@type anononly: boolean
@param nocreate: Prevent account creation.
@@ -5325,7 +5307,7 @@
return data
@need_right('unblock')
- def unblockuser(self, user, reason=None):
+ def unblockuser(self, user, reason: Optional[str] = None):
"""
Remove the block for the user.
@@ -5334,7 +5316,6 @@
@param user: The username/IP without a namespace.
@type user: L{pywikibot.User}
@param reason: Reason for the unblock.
- @type reason: basestring
"""
req = self._simple_request(action='unblock',
user=user.username,
@@ -5345,7 +5326,7 @@
return data
@need_right('editmywatchlist')
- def watch(self, pages, unwatch=False):
+ def watch(self, pages, unwatch=False) -> bool:
"""Add or remove pages from watchlist.
@see: U{https://www.mediawiki.org/wiki/API:Watch}
@@ -5356,7 +5337,6 @@
@param unwatch: If True, remove pages from watchlist;
if False add them (default).
@return: True if API returned expected response; False otherwise
- @rtype: bool
@raises KeyError: 'watch' isn't in API response
"""
@@ -5387,7 +5367,7 @@
@need_right('editmywatchlist')
@deprecated('Site().watch', since='20160102')
- def watchpage(self, page, unwatch=False):
+ def watchpage(self, page, unwatch=False) -> bool:
"""
Add or remove page from watchlist.
@@ -5398,7 +5378,6 @@
@param unwatch: If True, remove page from watchlist;
if False (default), add it.
@return: True if API returned expected response; False otherwise
- @rtype: bool
"""
try:
@@ -5409,10 +5388,10 @@
return result
@need_right('purge')
- def purgepages(
- self, pages, forcelinkupdate=False, forcerecursivelinkupdate=False,
- converttitles=False, redirects=False
- ):
+ def purgepages(self, pages, forcelinkupdate: bool = False,
+ forcerecursivelinkupdate: bool = False,
+ converttitles: bool = False, redirects: bool = False
+ ) -> bool:
"""
Purge the server's cache for one or multiple pages.
@@ -5422,14 +5401,10 @@
@param converttitles: Convert titles to other variants if necessary.
Only works if the wiki's content language supports variant
conversion.
- @type converttitles: bool
@param forcelinkupdate: Update the links tables.
- @type forcelinkupdate: bool
@param forcerecursivelinkupdate: Update the links table, and update the
links tables for any page that uses this page as a template.
- @type forcerecursivelinkupdate: bool
@return: True if API returned expected response; False otherwise
- @rtype: bool
"""
req = self._simple_request(action='purge', titles=list(set(pages)))
if converttitles:
@@ -5507,8 +5482,8 @@
@deprecate_arg('imagepage', 'filepage')
def upload(self, filepage, source_filename=None, source_url=None,
comment=None, text=None, watch=False, ignore_warnings=False,
- chunk_size=0, _file_key=None, _offset=0, _verify_stash=None,
- report_success=None):
+ chunk_size: int = 0, _file_key: Optional[str] = None,
+ _offset=0, _verify_stash=None, report_success=None):
"""
Upload a file to the wiki.
@@ -5540,10 +5515,8 @@
U{https://www.mediawiki.org/wiki/API:Upload#Chunked_uploading}). It
will only upload in chunks, if the version number is 1.20 or higher
and the chunk size is positive but lower than the file size.
- @type chunk_size: int
@param _file_key: Reuses an already uploaded file using the filekey. If
None (default) it will upload the file.
- @type _file_key: str or None
@param _offset: When file_key is not None this can be an integer to
continue a previously canceled chunked upload. If False it treats
that as a finished upload. If True it requests the stash info from
@@ -5924,7 +5897,7 @@
address (str), comment (str).
@param namespaces: only iterate pages in these namespaces
- @type namespaces: iterable of basestring or Namespace key,
+ @type namespaces: iterable of str or Namespace key,
or a single instance of those types. May be a '|' separated
list of namespace identifiers.
@raises KeyError: a namespace identifier was not resolved
@@ -6306,7 +6279,7 @@
@type total: int
@param namespaces: only iterate pages in these namespaces
- @type namespaces: iterable of basestring or Namespace key,
+ @type namespaces: iterable of str or Namespace key,
or a single instance of those types. May be a '|' separated
list of namespace identifiers.
diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index e0b2d4c..6e17b3d 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -252,14 +252,13 @@
Raises TypeError if write attempted.
"""
- def __init__(self, data=None, error=None):
+ def __init__(self, data=None, error: Optional[str] = None):
"""
Initializer.
@param data: mapping to freeze
@type data: mapping
@param error: error message
- @type error: basestring
"""
if data:
args = [data]
@@ -1538,8 +1537,11 @@
return decorator
-def redirect_func(target, source_module=None, target_module=None,
- old_name=None, class_name=None, since=None,
+def redirect_func(target, source_module: Optional[str] = None,
+ target_module: Optional[str] = None,
+ old_name: Optional[str] = None,
+ class_name: Optional[str] = None,
+ since: Optional[str] = None,
future_warning=False):
"""
Return a function which can be used to redirect to 'target'.
@@ -1552,20 +1554,15 @@
@param source_module: The module of the old function. If '.' defaults
to target_module. If 'None' (default) it tries to guess it from the
executing function.
- @type source_module: basestring
@param target_module: The module of the target function. If
'None' (default) it tries to get it from the target. Might not work
with nested classes.
- @type target_module: basestring
@param old_name: The old function name. If None it uses the name of the
new function.
- @type old_name: basestring
@param class_name: The name of the class. It's added to the target and
source module (separated by a '.').
- @type class_name: basestring
@param since: a timestamp string of the date when the method was
deprecated (form 'YYYYMMDD') or a version string.
- @type since: str
@param future_warning: if True a FutureWarning will be thrown,
otherwise it defaults to DeprecationWarning
@type future_warning: bool
@@ -1623,8 +1620,10 @@
sys.modules[module.__name__] = self
def _add_deprecated_attr(self, name: str, replacement=None,
- replacement_name=None, warning_message=None,
- since=None, future_warning=False):
+ replacement_name: Optional[str] = None,
+ warning_message: Optional[str] = None,
+ since: Optional[str] = None,
+ future_warning: bool = False):
"""
Add the name to the local deprecated names dict.
@@ -1638,16 +1637,12 @@
if C{replacement} is not None and it has no __name__ attribute.
If it contains a '.', it will be interpreted as a Python dotted
object name, and evaluated when the deprecated object is needed.
- @type replacement_name: str
@param warning_message: The warning to display, with positional
variables: {0} = module, {1} = attribute name, {2} = replacement.
- @type warning_message: basestring
@param since: a timestamp string of the date when the method was
deprecated (form 'YYYYMMDD') or a version string.
- @type since: str
@param future_warning: if True a FutureWarning will be thrown,
otherwise it defaults to DeprecationWarning
- @type future_warning: bool
"""
if '.' in name:
raise ValueError('Deprecated name "{}" may not contain '
diff --git a/tests/api_tests.py b/tests/api_tests.py
index 98684d3..4dce5c7 100644
--- a/tests/api_tests.py
+++ b/tests/api_tests.py
@@ -1088,8 +1088,8 @@
self.assertEqual(result, expect)
self.assertIsInstance(result, str)
- def test_url_encoding_from_basestring(self):
- """Test encoding basestring values."""
+ def test_url_encoding_from_str(self):
+ """Test encoding str values."""
query = {'token': 'test\xe2\x80\x94test'}
expect = 'token=test%C3%A2%C2%80%C2%94test'
result = api.encode_url(query)
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/635380
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: I20444cde3e5e857935b3dd35ca6ca13845cad455
Gerrit-Change-Number: 635380
Gerrit-PatchSet: 3
Gerrit-Owner: Udoka <UdokakuUgochukwu(a)gmail.com>
Gerrit-Reviewer: Reviewer-bot <gerritreviewerbot(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-MessageType: merged