jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/634216 )
Change subject: [IMPR] Replaced basestring by str ......................................................................
[IMPR] Replaced basestring by str
Bug: T265128 Change-Id: I6c979c73947dd2f7b25770d93a4eccfe7256a6a9 --- M pywikibot/comms/eventstreams.py M pywikibot/data/sparql.py M pywikibot/data/wikistats.py M pywikibot/site_detect.py M pywikibot/textlib.py M pywikibot/throttle.py M pywikibot/version.py 7 files changed, 27 insertions(+), 38 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/comms/eventstreams.py b/pywikibot/comms/eventstreams.py index 472b36b..be525cd 100644 --- a/pywikibot/comms/eventstreams.py +++ b/pywikibot/comms/eventstreams.py @@ -18,6 +18,8 @@ import json import socket
+from typing import Optional + from requests import __version__ as requests_version from requests.packages.urllib3.exceptions import ProtocolError from requests.packages.urllib3.response import httplib @@ -157,7 +159,7 @@ if self._since else ''))) return self._url
- def set_maximum_items(self, value): + def set_maximum_items(self, value: int): """ Set the maximum number of items to be retrieved from the stream.
@@ -166,7 +168,6 @@
@param value: The value of maximum number of items to be retrieved in total to set. - @type value: int """ if value is not None: self._total = int(value) @@ -261,13 +262,12 @@ else: self.filter[ftype].append(partial(_in, key=key, value=value))
- def streamfilter(self, data): + def streamfilter(self, data: dict): """Filter function for eventstreams.
See the description of register_filter() how it works.
@param data: event data dict used by filter functions - @type data: dict """ if any(function(data) for function in self.filter['none']): return False @@ -328,13 +328,12 @@ del self.source
-def site_rc_listener(site, total=None): +def site_rc_listener(site, total: Optional[int] = None): """Yield changes received from EventStream.
@param site: the Pywikibot.Site object to yield live recent changes for @type site: Pywikibot.BaseSite @param total: the maximum number of changes to return - @type total: int
@return: pywikibot.comms.eventstream.rc_listener configured for given site @raises ImportError: sseclient installation is required diff --git a/pywikibot/data/sparql.py b/pywikibot/data/sparql.py index 697ac29..9d58deb 100644 --- a/pywikibot/data/sparql.py +++ b/pywikibot/data/sparql.py @@ -7,6 +7,7 @@ # import json
+from typing import Optional from urllib.parse import quote
from requests.exceptions import Timeout @@ -27,26 +28,25 @@ This class allows to run SPARQL queries against any SPARQL endpoint. """
- def __init__(self, endpoint=None, entity_url=None, repo=None, - max_retries=None, retry_wait=None): + def __init__(self, + endpoint: Optional[str] = None, + entity_url: Optional[str] = None, repo=None, + max_retries: Optional[int] = None, + retry_wait: Optional[float] = None): """ Create endpoint.
@param endpoint: SPARQL endpoint URL - @type endpoint: str @param entity_url: URL prefix for any entities returned in a query. - @type entity_url: str @param repo: The Wikibase site which we want to run queries on. If provided this overrides any value in endpoint and entity_url. Defaults to Wikidata. @type repo: pywikibot.site.DataSite @param max_retries: (optional) Maximum number of times to retry after errors, defaults to config.max_retries. - @type max_retries: int @param retry_wait: (optional) Minimum time in seconds to wait after an error, defaults to config.retry_wait seconds (doubles each retry until config.retry_max is reached). - @type retry_wait: float """ # default to Wikidata if not repo and not endpoint: @@ -91,7 +91,8 @@ """ return self.last_response
- def select(self, query: str, full_data=False, headers=DEFAULT_HEADERS): + def select(self, query: str, full_data: bool = False, + headers=DEFAULT_HEADERS): """ Run SPARQL query and return the result.
@@ -100,7 +101,6 @@
@param query: Query text @param full_data: Whether return full data objects or only values - @type full_data: bool @return: List of query results or None if query failed """ data = self.query(query, headers=headers) diff --git a/pywikibot/data/wikistats.py b/pywikibot/data/wikistats.py index b163d62..ba66f09 100644 --- a/pywikibot/data/wikistats.py +++ b/pywikibot/data/wikistats.py @@ -118,12 +118,11 @@ self._raw[format][table] = data return data
- def csv(self, table: str): + def csv(self, table: str) -> list: """ Fetch and parse CSV for a table.
@param table: table of data to fetch - @rtype: list """ if table in self._data['csv']: return self._data['csv'][table] @@ -136,12 +135,11 @@
return data
- def xml(self, table: str): + def xml(self, table: str) -> list: """ Fetch and parse XML for a table.
@param table: table of data to fetch - @rtype: list """ if table in self._data['xml']: return self._data['xml'][table] @@ -163,11 +161,10 @@ self._data['xml'][table] = data return data
- def get(self, table: str, format='csv'): + def get(self, table: str, format='csv') -> list: """Get a list of a table of data.
@param table: table of data to fetch - @rtype: list """ try: func = getattr(self, format) @@ -176,13 +173,12 @@ .format(format)) return func(table)
- def get_dict(self, table: str, format='csv'): + def get_dict(self, table: str, format='csv') -> dict: """Get dictionary of a table of data using format.
@param table: table of data to fetch @param format: format of data to use @type format: 'xml' or 'csv', or None to autoselect. - @rtype: dict """ if format is None: # old autoselect format = 'csv' diff --git a/pywikibot/site_detect.py b/pywikibot/site_detect.py index 4e9b100..7f805e6 100644 --- a/pywikibot/site_detect.py +++ b/pywikibot/site_detect.py @@ -9,6 +9,7 @@
from contextlib import suppress from html.parser import HTMLParser +from typing import Optional from urllib.parse import urljoin, urlparse from requests.exceptions import RequestException
@@ -170,12 +171,8 @@ return hash(self.server + self.scriptpath)
@property - def api(self): - """ - Get api URL. - - @rtype: str or None - """ + def api(self) -> Optional[str]: + """Get api URL.""" if self.server is None or self.scriptpath is None: return
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py index 7d6ea80..481608a 100644 --- a/pywikibot/textlib.py +++ b/pywikibot/textlib.py @@ -602,7 +602,6 @@ remaining.
@param text: the text in which to replace links - @type text: basestring @param replace: either a callable which reacts like described above. The callable must accept four parameters link, text, groups, rng and allows for user interaction. The groups are a dict containing 'title', @@ -639,7 +638,7 @@ """Normalize the replacement into a list.""" if not isinstance(replacement, (pywikibot.Page, pywikibot.Link)): raise ValueError('The replacement must be None, False, ' - 'a sequence, a Link or a basestring but ' + 'a sequence, a Link or a str but ' 'is "{0}"'.format(type(replacement)))
def title_section(link) -> str: @@ -655,7 +654,7 @@ replace_list = [to_link(replace[0]), replace[1]] if not isinstance(replace_list[0], pywikibot.Link): raise ValueError( - 'The original value must be either basestring, Link or Page ' + 'The original value must be either str, Link or Page ' 'but is "{0}"'.format(type(replace_list[0]))) if replace_list[1] is not False and replace_list[1] is not None: if isinstance(replace_list[1], str): @@ -756,7 +755,7 @@ raise ValueError('The result must be unicode (str in Python 3) ' 'and not bytes (str in Python 2).')
- # Verify that it's either Link, Page or basestring + # Verify that it's either Link, Page or str check_classes(new_link) # Use section and label if it's a Link and not otherwise if isinstance(new_link, pywikibot.Link): @@ -1562,7 +1561,7 @@ # --------------------------------
def extract_templates_and_params(text: str, remove_disabled_parts=None, - strip=None): + strip: Optional[bool] = None): """Return a list of templates found in text.
Return value is a list of tuples. There is one tuple for each use of a @@ -1597,7 +1596,6 @@ @param strip: if enabled, strip arguments and values of templates. If None (default), this is enabled when mwparserfromhell is not available and disabled if mwparserfromhell is present. - @type strip: bool @return: list of template name and params @rtype: list of tuple """ diff --git a/pywikibot/throttle.py b/pywikibot/throttle.py index 6b5ce1f..02c37b8 100644 --- a/pywikibot/throttle.py +++ b/pywikibot/throttle.py @@ -10,6 +10,7 @@ import time
from contextlib import suppress +from typing import Optional
import pywikibot from pywikibot import config @@ -267,7 +268,7 @@ else: self.last_read = time.time()
- def lag(self, lagtime=None): + def lag(self, lagtime: Optional[float] = None): """Seize the throttle lock due to server lag.
Usually the self.retry-after value from response_header of the last @@ -284,7 +285,6 @@ @param lagtime: The time to wait for the next request which is the last maxlag time from api warning. This is only used as a fallback if self.retry-after isn't set. - @type lagtime: float """ started = time.time() with self.lock: diff --git a/pywikibot/version.py b/pywikibot/version.py index 45a77d0..e6cdd67 100644 --- a/pywikibot/version.py +++ b/pywikibot/version.py @@ -386,7 +386,7 @@
@deprecated('get_module_version, get_module_filename and get_module_mtime', since='20150221', future_warning=True) -def getfileversion(filename): +def getfileversion(filename: str): """Retrieve revision number of file.
Extracts __version__ variable containing Id tag, without importing it. @@ -396,7 +396,6 @@ returned. Because it doesn't import it, the version can be retrieved from any file. @param filename: Name of the file to get version - @type filename: str """ _program_dir = _get_program_dir() __version__ = None