jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1222701?usp=email )
Change subject: [IMPR] BaseSite.__getattr__: Use direct __code__ inspection for performance
......................................................................
[IMPR] BaseSite.__getattr__: Use direct __code__ inspection for performance
Instead of inspect.signature(), __getattr__ now inspects the method's
__code__ object to determine the first parameter. This avoids expensive
generic callable introspection in this hot path. It is ~16× faster than
the old implementation; the overhead is only 60% against direct lookup.
Bug: T413398
Change-Id: Ib9cdf3884498de9d1624dfd5b9ef428116719959
---
M docs/api_ref/pywikibot.site.rst
M pywikibot/site/_basesite.py
2 files changed, 28 insertions(+), 9 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/docs/api_ref/pywikibot.site.rst b/docs/api_ref/pywikibot.site.rst
index 6fe32e4..bbacc29 100644
--- a/docs/api_ref/pywikibot.site.rst
+++ b/docs/api_ref/pywikibot.site.rst
@@ -18,6 +18,8 @@
.. automodule:: pywikibot.site._basesite
.. autoclass:: BaseSite
+ :members:
+ :special-members: __getattr__
.. method:: category_redirects(fallback: str = '_default')
diff --git a/pywikibot/site/_basesite.py b/pywikibot/site/_basesite.py
index 24bdcbe..d234f27 100644
--- a/pywikibot/site/_basesite.py
+++ b/pywikibot/site/_basesite.py
@@ -1,6 +1,6 @@
"""Objects with site methods independent of the communication interface."""
#
-# (C) Pywikibot team, 2008-2025
+# (C) Pywikibot team, 2008-2026
#
# Distributed under the terms of the MIT license.
#
@@ -185,21 +185,38 @@
def __getattr__(self, name: str):
"""Delegate undefined methods calls to the Family object.
+ Only public :class:`Family instance methods are delegated.
+
+ A method is considered delegatable if:
+ - it is a bound instance method of Family,
+ - it is public (name does not start with '_'),
+ - its first logical parameter is *code*.
+
+ .. note::
+ For performance reasons, the method signature is inspected
+ via the method's ``__code__`` object instead of
+ ``inspect.signature()``. This avoids expensive generic
+ introspection in this hot path and is safe because Family
+ methods are guaranteed to be pure Python.
+
.. versionchanged:: 9.0
Only delegate to public Family methods which have ``code`` as
first parameter.
+ .. versionchanged:: 11.0
+ Use direct ``__code__`` inspection instead of
+ ``inspect.signature()`` to significantly improve attribute
+ access performance.
"""
if not name.startswith('_'):
obj = getattr(self.family, name, None)
if inspect.ismethod(obj):
- params = inspect.signature(obj).parameters
- if params:
- parameter = next(iter(params))
- if parameter == 'code':
- method = functools.partial(obj, self.code)
- if hasattr(obj, '__doc__'):
- method.__doc__ = obj.__doc__
- return method
+ code = obj.__code__
+ params = code.co_varnames[:code.co_argcount]
+ if len(params) > 1 and params[1] == 'code':
+ method = functools.partial(obj, self.code)
+ if hasattr(obj, '__doc__'):
+ method.__doc__ = obj.__doc__
+ return method
raise AttributeError(f'{type(self).__name__} instance has no '
f'attribute {name!r}') from None
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1222701?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ib9cdf3884498de9d1624dfd5b9ef428116719959
Gerrit-Change-Number: 1222701
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1224896?usp=email )
Change subject: FIX: Handle limit value gracefully if it is an int
......................................................................
FIX: Handle limit value gracefully if it is an int
Bug: T414168
Change-Id: Ie49f8aeef067777fa5ba042a1330d2f68557e05a
---
M pywikibot/data/api/_requests.py
1 file changed, 6 insertions(+), 5 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/data/api/_requests.py b/pywikibot/data/api/_requests.py
index d77a0c6..a8289f0 100644
--- a/pywikibot/data/api/_requests.py
+++ b/pywikibot/data/api/_requests.py
@@ -1,6 +1,6 @@
"""Objects representing API requests."""
#
-# (C) Pywikibot team, 2007-2025
+# (C) Pywikibot team, 2007-2026
#
# Distributed under the terms of the MIT license.
#
@@ -9,6 +9,7 @@
import datetime
import hashlib
import inspect
+import math
import os
import pickle
import pprint
@@ -797,10 +798,10 @@
# there might also be an overflow, so try a smaller limit
for param in self._params:
if param.endswith('limit'):
- # param values are stored a list of str
- value = self[param][0]
- if value.isdigit():
- self[param] = [str(int(value) // 2)]
+ # param values are stored a list of str or int (T414168)
+ with suppress(ValueError):
+ value = int(self[param][0])
+ self[param] = [str(math.ceil(value / 2))]
pywikibot.info(f'Set {param} = {self[param]}')
else:
scheme = urlparse(response.url).scheme
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1224896?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ie49f8aeef067777fa5ba042a1330d2f68557e05a
Gerrit-Change-Number: 1224896
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1224753?usp=email )
Change subject: Fix Docsig's SIG402 issues
......................................................................
Fix Docsig's SIG402 issues
Bug: T413960
Change-Id: Id177c3c22c8e35e206de178f2c351adbfae876a5
---
M pyproject.toml
M pywikibot/page/_basepage.py
M pywikibot/pagegenerators/_generators.py
M pywikibot/site/_apisite.py
M pywikibot/site/_datasite.py
M pywikibot/site/_generators.py
M pywikibot/tools/__init__.py
7 files changed, 28 insertions(+), 28 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pyproject.toml b/pyproject.toml
index 37a2d06..a678cdf 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -166,7 +166,6 @@
"SIG203",
"SIG301",
"SIG305",
- "SIG402",
"SIG501",
"SIG503",
"SIG505",
diff --git a/pywikibot/page/_basepage.py b/pywikibot/page/_basepage.py
index db6cacd..e1bf8f1 100644
--- a/pywikibot/page/_basepage.py
+++ b/pywikibot/page/_basepage.py
@@ -1,6 +1,6 @@
"""Objects representing a base object for a MediaWiki page."""
#
-# (C) Pywikibot team, 2008-2025
+# (C) Pywikibot team, 2008-2026
#
# Distributed under the terms of the MIT license.
#
@@ -2055,13 +2055,13 @@
:param reason: The edit summary for the deletion, or rationale
for deletion if requesting. If None, ask for it.
- :param deletetalk: Also delete the talk page, if it exists.
:param prompt: If true, prompt user for confirmation before deleting.
:param mark: If true, and user does not have sysop rights, place a
speedy-deletion request on the page instead. If false, non-sysops
will be asked before marking pages for deletion.
:param automatic_quit: show also the quit option, when asking
for confirmation.
+ :param deletetalk: Also delete the talk page, if it exists.
:return: the function returns an integer, with values as follows:
value meaning
@@ -2283,6 +2283,8 @@
<pywikibot.site._apisite.APISite.protect>`
- :meth:`applicable_protections`
+ :param reason: Reason for the action, default is None and will
+ set an empty string.
:param protections: A dict mapping type of protection to
protection level of that type. Allowed protection types for
a page can be retrieved by :meth:`applicable_protections`.
@@ -2291,8 +2293,6 @@
Example: :code:`{'move': 'sysop', 'edit': 'autoconfirmed'}`
- :param reason: Reason for the action, default is None and will
- set an empty string.
"""
protections = protections or {} # protections is converted to {}
reason = reason or '' # None is converted to ''
diff --git a/pywikibot/pagegenerators/_generators.py b/pywikibot/pagegenerators/_generators.py
index 6286bca..f51afb9 100644
--- a/pywikibot/pagegenerators/_generators.py
+++ b/pywikibot/pagegenerators/_generators.py
@@ -1,6 +1,6 @@
"""Page filter generators provided by the pagegenerators module."""
#
-# (C) Pywikibot team, 2008-2025
+# (C) Pywikibot team, 2008-2026
#
# Distributed under the terms of the MIT license.
#
@@ -508,9 +508,10 @@
) -> Iterable[pywikibot.page.Page]:
"""Yield unique pages edited by user:username.
- :param total: Maximum number of pages to retrieve in total
+ :param username: user name
:param namespaces: list of namespace numbers to fetch contribs from
:param site: Site for generator results.
+ :param total: Maximum number of pages to retrieve in total
"""
if site is None:
site = pywikibot.Site()
diff --git a/pywikibot/site/_apisite.py b/pywikibot/site/_apisite.py
index bbe13aa..8bc880d 100644
--- a/pywikibot/site/_apisite.py
+++ b/pywikibot/site/_apisite.py
@@ -1,6 +1,6 @@
"""Objects representing API interface to MediaWiki site."""
#
-# (C) Pywikibot team, 2008-2025
+# (C) Pywikibot team, 2008-2026
#
# Distributed under the terms of the MIT license.
#
@@ -2009,6 +2009,8 @@
:param minor: if True (default), mark edit as minor
:param notminor: if True, override account preferences to mark
edit as non-minor
+ :param bot: if True and bot right is given, mark edit with bot
+ flag
:param recreate: if True (default), create new page even if this
title has previously been deleted
:param createonly: if True, raise an error if this title already
@@ -2025,8 +2027,6 @@
* nochange --- don't change the watchlist
If None (default), follow bot account's default settings
- :param bot: if True and bot right is given, mark edit with bot
- flag
:keyword str text: Overrides Page.text
:keyword int | str section: Edit an existing numbered section or
@@ -3073,14 +3073,14 @@
"""Purge the server's cache for one or multiple pages.
:param pages: list of Page objects
- :param redirects: Automatically resolve redirects.
- :param converttitles: Convert titles to other variants if
- necessary. Only works if the wiki's content language
- supports variant conversion.
:param forcelinkupdate: Update the links tables.
:param forcerecursivelinkupdate: Update the links table, and
update the links tables for any page that uses this page as
a template.
+ :param converttitles: Convert titles to other variants if
+ necessary. Only works if the wiki's content language
+ supports variant conversion.
+ :param redirects: Automatically resolve redirects.
:return: True if API returned expected response; False otherwise
"""
req = self.simple_request(action='purge', titles=list(set(pages)))
diff --git a/pywikibot/site/_datasite.py b/pywikibot/site/_datasite.py
index 7b66e93..3d99e55 100644
--- a/pywikibot/site/_datasite.py
+++ b/pywikibot/site/_datasite.py
@@ -442,8 +442,8 @@
*tags* parameter was added
:param claim: The claim to save
- :param bot: Whether to mark the edit as a bot edit
:param summary: Edit summary
+ :param bot: Whether to mark the edit as a bot edit
:param tags: Change tags to apply to the revision
:raises NoPageError: missing the the snak value
:raises NotImplementedError: ``claim.isReference`` or
@@ -782,10 +782,10 @@
def set_redirect_target(self, from_item, to_item, bot: bool = True):
"""Make a redirect to another item.
- :param to_item: Title of target item.
- :type to_item: pywikibot.ItemPage
:param from_item: Title of the item to be redirected.
:type from_item: pywikibot.ItemPage
+ :param to_item: Title of target item.
+ :type to_item: pywikibot.ItemPage
:param bot: Whether to mark the edit as a bot edit
"""
params = {
diff --git a/pywikibot/site/_generators.py b/pywikibot/site/_generators.py
index 8b15ad1..7ad4230 100644
--- a/pywikibot/site/_generators.py
+++ b/pywikibot/site/_generators.py
@@ -1,6 +1,6 @@
"""Objects representing API generators to MediaWiki site."""
#
-# (C) Pywikibot team, 2008-2025
+# (C) Pywikibot team, 2008-2026
#
# Distributed under the terms of the MIT license.
#
@@ -1253,10 +1253,10 @@
:param url: The URL to search for (with or without the protocol
prefix); this may include a '*' as a wildcard, only at the start
of the hostname
- :param namespaces: list of namespace numbers to fetch contribs from
- :param total: Maximum number of pages to retrieve in total
:param protocol: protocol to search for, http and https by default.
Full list shown on Special:LinkSearch wikipage
+ :param namespaces: list of namespace numbers to fetch contribs from
+ :param total: Maximum number of pages to retrieve in total
"""
if url is not None:
found_protocol, _, url = url.rpartition('://')
@@ -1695,15 +1695,15 @@
.. seealso:: :api:`Deletedrevisions`
:param titles: The page titles to check for deleted revisions
- :keyword revids: Get revisions by their ID
-
- .. note:: either titles or revids must be set but not both
-
:param start: Iterate revisions starting at this Timestamp
:param end: Iterate revisions ending at this Timestamp
:param reverse: Iterate oldest revisions first (default: newest)
:param content: If True, retrieve the content of each revision
:param total: number of revisions to retrieve
+ :keyword revids: Get revisions by their ID
+
+ .. note:: either titles or revids must be set but not both
+
:keyword user: List revisions by this user
:keyword excludeuser: Exclude revisions by this user
:keyword tag: Only list revision tagged with this tag
diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index 9ad6b55..bdced85 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -1,6 +1,6 @@
"""Miscellaneous helper functions (not wiki-dependent)."""
#
-# (C) Pywikibot team, 2008-2025
+# (C) Pywikibot team, 2008-2026
#
# Distributed under the terms of the MIT license.
#
@@ -556,12 +556,12 @@
.. versionadded:: 3.0
:param filename: The filename.
- :param use_extension: Use the file extension instead of the magic
- number to determine the type of compression (default True). Must
- be True when writing or appending.
:param mode: The mode in which the file should be opened. It may
either be 'r', 'rb', 'a', 'ab', 'w' or 'wb'. All modes open the
file in binary mode. It defaults to 'rb'.
+ :param use_extension: Use the file extension instead of the magic
+ number to determine the type of compression (default True). Must
+ be True when writing or appending.
:raises ValueError: When 7za is not available or the opening mode is
unknown or it tries to write a 7z archive.
:raises FileNotFoundError: When the filename doesn't exist and it
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1224753?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Id177c3c22c8e35e206de178f2c351adbfae876a5
Gerrit-Change-Number: 1224753
Gerrit-PatchSet: 2
Gerrit-Owner: Sanjai Siddharthan <sanjaisiddharth2002(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Xqt has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1224751?usp=email )
Change subject: doc: Fall back to Sphinx 8.2.3 to enable online documentation again
......................................................................
doc: Fall back to Sphinx 8.2.3 to enable online documentation again
Bug: T413563
Change-Id: I6a5b68ba65436f97d4e158fb22e3f39ae860b61e
---
M docs/conf.py
M docs/requirements.txt
2 files changed, 2 insertions(+), 2 deletions(-)
Approvals:
Xqt: Verified; Looks good to me, approved
jenkins-bot: Verified
diff --git a/docs/conf.py b/docs/conf.py
index ff6d4be..24effa5 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -47,7 +47,7 @@
# If your documentation needs a minimal Sphinx version, state it here.
#
-needs_sphinx = '9.1.0'
+needs_sphinx = '8.2.3'
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
diff --git a/docs/requirements.txt b/docs/requirements.txt
index e03a460..8863b4f 100644
--- a/docs/requirements.txt
+++ b/docs/requirements.txt
@@ -1,7 +1,7 @@
# This is a PIP requirements file for building Sphinx documentation of Pywikibot
# ../requirements.txt is also needed.
# Note: Python 3.11 is required for sphinx 8.2+
-sphinx >= 9.1.0
+sphinx == 8.2.3
rstcheck >=6.2.5
sphinxext-opengraph >= 0.13.0
sphinx-copybutton >= 0.5.2
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1224751?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I6a5b68ba65436f97d4e158fb22e3f39ae860b61e
Gerrit-Change-Number: 1224751
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/i18n/+/1224651?usp=email )
Change subject: Localisation updates from https://translatewiki.net.
......................................................................
Localisation updates from https://translatewiki.net.
Change-Id: I36475842f5be5e155b7f28c6418e8acbec9c65cf
---
M redirect/es.json
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
jenkins-bot: Verified
L10n-bot: Looks good to me, approved
diff --git a/redirect/es.json b/redirect/es.json
index e670d65..93b3602 100644
--- a/redirect/es.json
+++ b/redirect/es.json
@@ -11,7 +11,7 @@
"Xqt"
]
},
- "redirect-fix-broken-moved": "corrección de redirección rota hacia la página de destino trasladada «%(to)s»",
+ "redirect-fix-broken-moved": "corrección de redirección rota desde «%(from)s» hacia la página de destino trasladada «%(to)s»",
"redirect-fix-double": "corrección de redirección doble a %(to)s",
"redirect-fix-loop": "corrección de redirección infinita a %(to)s",
"redirect-remove-broken": "redirige a una página borrada o que no existe",
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/i18n/+/1224651?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/i18n
Gerrit-Branch: master
Gerrit-Change-Id: I36475842f5be5e155b7f28c6418e8acbec9c65cf
Gerrit-Change-Number: 1224651
Gerrit-PatchSet: 1
Gerrit-Owner: L10n-bot <l10n-bot(a)translatewiki.net>
Gerrit-Reviewer: L10n-bot <l10n-bot(a)translatewiki.net>
Gerrit-Reviewer: jenkins-bot
Xqt has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1224129?usp=email )
Change subject: [CI] Exclude coverage for GraalPy 25 on Ubuntu
......................................................................
[CI] Exclude coverage for GraalPy 25 on Ubuntu
GraalPy 25 exhibits severe performance regressions with coverage enabled on
Linux runners, causing test jobs to be extremely slow or flaky. To keep
the CI practical, disable coverage only for GraalPy 25 on Ubuntu, while
retaining coverage for all other Python versions and platforms.
- Run pytest without coverage for GraalPy 25 on Ubuntu
- Keep coverage GraalPy 24.x and other os
- No change to test logic, only coverage collection
Bug: T413596
Change-Id: I446c0e087b785a30b890ba381c793370b7aadad3
---
M .github/workflows/graalpy_tests.yml
1 file changed, 9 insertions(+), 2 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/.github/workflows/graalpy_tests.yml b/.github/workflows/graalpy_tests.yml
index 146e63f..8e4434e 100644
--- a/.github/workflows/graalpy_tests.yml
+++ b/.github/workflows/graalpy_tests.yml
@@ -50,7 +50,7 @@
- name: Generate user files
run: |
python -Werror::UserWarning -m pwb generate_user_files -site:${{matrix.site}} -v -debug;
- - name: Test with unittest or pytest
+ - name: Test with pytest
id: ci_test
continue-on-error: true
timeout-minutes: 110
@@ -59,7 +59,14 @@
PYWIKIBOT_TEST_NO_RC: 1
run: |
python pwb.py version
- coverage run -m pytest -k "not TestDate" -a "not net" --ignore=tests/script_tests.py
+ TEST_CMD="pytest -k 'not TestDate' -a 'not net' --ignore=tests/script_tests.py"
+ if [[ "${{ matrix.python-version }}" == "graalpy-25.0" && "${{ matrix.os }}" == "ubuntu-latest" ]]; then
+ echo "Running tests without coverage (GraalPy 25 on Ubuntu)"
+ $TEST_CMD
+ else
+ echo "Running tests with coverage"
+ coverage run -m $TEST_CMD
+ fi
- name: Show coverage statistics
run: |
coverage combine || true
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1224129?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I446c0e087b785a30b890ba381c793370b7aadad3
Gerrit-Change-Number: 1224129
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1224028?usp=email )
Change subject: doc: Update type hints for some http functions
......................................................................
doc: Update type hints for some http functions
Update type hints for http.user_agent_username,
http.error_handling_callback and http.fetch
Change-Id: Ic9a6d38b6dd38bc7d7a31f6e4d37c1dec4f327bf
---
M pywikibot/comms/http.py
1 file changed, 13 insertions(+), 10 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index 6dd8923..a4758d1 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -168,7 +168,7 @@
_USER_AGENT_FORMATTER = _UserAgentFormatter()
-def user_agent_username(username=None):
+def user_agent_username(username=None) -> str:
"""Reduce username to a representation permitted in HTTP headers.
To achieve that, this function:
@@ -313,11 +313,11 @@
return None
-def error_handling_callback(response) -> None:
+def error_handling_callback(response: requests.Response | Exception) -> None:
"""Raise exceptions and log alerts.
- :param response: Response returned by Session.request().
- :type response: :py:obj:`requests.Response`
+ :param response: Response returned by Session.request() or Exception
+ raised during request.
"""
# TODO: do some error correcting stuff
if isinstance(response, requests.exceptions.SSLError) \
@@ -366,9 +366,12 @@
warning(f'Http response status {response.status_code}')
-def fetch(uri: str, method: str = 'GET', headers: dict | None = None,
+def fetch(uri: str,
+ method: str = 'GET',
+ headers: dict[str, str] | None = None,
default_error_handling: bool = True,
- use_fake_user_agent: bool | str = False, **kwargs):
+ use_fake_user_agent: bool | str = False,
+ **kwargs) -> requests.Response:
"""HTTP request.
See :py:obj:`requests.Session.request` for parameters.
@@ -381,15 +384,14 @@
pywikibot's UA, str to specify own UA. This behaviour might be
overridden by domain in config.
- :keyword charset: Either a valid charset (usable for str.decode()) or None
- to automatically chose the charset from the returned header (defaults
- to latin-1)
+ :keyword charset: Either a valid charset (usable for str.decode())
+ or None to automatically chose the charset from the returned
+ header (defaults to latin-1)
:type charset: CodecInfo, str, None
:keyword verify: Verify the SSL certificate (default is True)
:type verify: bool or path to certificates
:keyword callbacks: Methods to call once data is fetched
:type callbacks: list of callable
- :rtype: :py:obj:`requests.Response`
"""
# Change user agent depending on fake UA settings.
# Set header to new UA if needed.
@@ -457,6 +459,7 @@
response.encoding = _decide_encoding(response, charset)
for callback in callbacks:
+ # Note: error_handling_callback raises the Exception
callback(response)
return response
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1224028?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ic9a6d38b6dd38bc7d7a31f6e4d37c1dec4f327bf
Gerrit-Change-Number: 1224028
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot