jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1312577?usp=email )
Change subject: tests: Use assertRaisesRegex instead of assertRaises
......................................................................
tests: Use assertRaisesRegex instead of assertRaises
Replace assertRaises with assertRaisesRegex in TestApiTimeoutError so
the tests verify the exception message in addition to its type. This
matters especially for the MaxlagTimeoutError case: because it is a
subclass of ApiTimeoutError, assertRaises alone could not tell the two
apart, whereas matching the message pins down the exact exception.
Bug: T154281
Change-Id: I7974a3081126344698c7b67d166ea550c175094c
---
M tests/exceptions_tests.py
1 file changed, 2 insertions(+), 2 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/exceptions_tests.py b/tests/exceptions_tests.py
index 96d1925..2c36752 100755
--- a/tests/exceptions_tests.py
+++ b/tests/exceptions_tests.py
@@ -28,10 +28,10 @@
def test_raise_catch(self) -> None:
"""Test raising and catching ApiTimeoutError."""
- with self.assertRaises(ApiTimeoutError):
+ with self.assertRaisesRegex(ApiTimeoutError, 'Test timeout'):
raise ApiTimeoutError('Test timeout')
- with self.assertRaises(ApiTimeoutError):
+ with self.assertRaisesRegex(ApiTimeoutError, 'Test maxlag timeout'):
raise MaxlagTimeoutError('Test maxlag timeout')
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1312577?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: I7974a3081126344698c7b67d166ea550c175094c
Gerrit-Change-Number: 1312577
Gerrit-PatchSet: 1
Gerrit-Owner: Sydneynoh <sydneycnoh(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/+/1312272?usp=email )
Change subject: Rename _altlang to public altlang
......................................................................
Rename _altlang to public altlang
The _altlang function is used outside the i18n module (e.g. in
reflinks.py), so it should be public rather than private. Renamed
to altlang() and kept _altlang as a deprecated alias for backward
compatibility.
Bug: T432543
Change-Id: I9e0f83e4b97f5c58670e8d7cb776d808eaf8f45b
---
M AUTHORS.rst
M pywikibot/i18n.py
M scripts/reflinks.py
M scripts/weblinkchecker.py
4 files changed, 9 insertions(+), 5 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/AUTHORS.rst b/AUTHORS.rst
index b797aa9..8fe8cc3 100644
--- a/AUTHORS.rst
+++ b/AUTHORS.rst
@@ -263,6 +263,7 @@
pietrodn
Platonides
Priyanka
+ Priyankar Shukla
Purodha B Blissenbach
Pyfisch
diff --git a/pywikibot/i18n.py b/pywikibot/i18n.py
index c8aaf3c..5e1eb1a 100644
--- a/pywikibot/i18n.py
+++ b/pywikibot/i18n.py
@@ -392,7 +392,7 @@
return _messages_available
-def _altlang(lang: str) -> list[str]:
+def altlang(lang: str) -> list[str]:
"""Define fallback languages for particular languages.
If no translation is available to a specified language, translate() will
@@ -404,6 +404,9 @@
This code is used by other translating methods below.
+ .. version-changed:: 11.6
+ renamed from :func:`_altlang`.
+
:param lang: The language code
:return: Language codes
"""
@@ -614,7 +617,7 @@
else:
codes = [code]
if fallback is True:
- codes += [*_altlang(code), '_default', 'en']
+ codes += [*altlang(code), '_default', 'en']
elif fallback is not False:
assert not isinstance(fallback, bool)
codes.extend(fallback)
@@ -807,7 +810,7 @@
# Prepare list of languages to try; fallback adds alternatives and English
langs = [lang]
if fallback:
- langs += [*_altlang(lang), 'en']
+ langs += [*altlang(lang), 'en']
# Try each language until a translation is found
for alt in langs:
diff --git a/scripts/reflinks.py b/scripts/reflinks.py
index 2dac3ad..47721cd 100755
--- a/scripts/reflinks.py
+++ b/scripts/reflinks.py
@@ -445,7 +445,7 @@
# Check
manual = 'mw:Manual:Pywikibot/refLinks'
code = None
- for alt in [self.site.code, *i18n._altlang(self.site.code)]:
+ for alt in [self.site.code, *i18n.altlang(self.site.code)]:
if alt in localized_msg:
code = alt
break
diff --git a/scripts/weblinkchecker.py b/scripts/weblinkchecker.py
index 3193611..165f322 100755
--- a/scripts/weblinkchecker.py
+++ b/scripts/weblinkchecker.py
@@ -256,7 +256,7 @@
# known fallback languages, then English, each with a
# decreasing quality value
lang = self.page.site.lang
- langs = [lang, *i18n._altlang(lang), 'en']
+ langs = [lang, *i18n.altlang(lang), 'en']
accept_language = ','.join(
code if i == 0 else f'{code};q={max(0.1, 1 - i * 0.2):.1f}'
for i, code in enumerate(langs)
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1312272?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: I9e0f83e4b97f5c58670e8d7cb776d808eaf8f45b
Gerrit-Change-Number: 1312272
Gerrit-PatchSet: 4
Gerrit-Owner: Priyankar22 <priyankarshukla22(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/+/1310525?usp=email )
Change subject: IMPR: Use new sentinel type in deprecation tests and api.Request
......................................................................
IMPR: Use new sentinel type in deprecation tests and api.Request
Change-Id: I730359f0a4862dc61ca1a8107aa4a22609d1718b
---
M pywikibot/data/api/_requests.py
M tests/aspects.py
2 files changed, 10 insertions(+), 10 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 5c5deda..8da3f14 100644
--- a/pywikibot/data/api/_requests.py
+++ b/pywikibot/data/api/_requests.py
@@ -28,6 +28,7 @@
import pywikibot
from pywikibot import config
+from pywikibot.backports import sentinel
from pywikibot.comms import http
from pywikibot.data import WaitingMixin
from pywikibot.exceptions import (
@@ -147,7 +148,7 @@
"""
# To make sure the default value of 'parameters' can be identified.
- _PARAM_DEFAULT = object()
+ PARAM_DEFAULT = sentinel('PARAM_DEFAULT')
def __init__(self, site=None,
mime: dict | None = None,
@@ -155,7 +156,7 @@
max_retries: int | None = None,
retry_wait: int | None = None,
use_get: bool | None = None,
- parameters=_PARAM_DEFAULT,
+ parameters: dict[str, Any] | sentinel = PARAM_DEFAULT,
**kwargs) -> None:
"""Create a new Request instance with the given parameters.
@@ -225,7 +226,7 @@
# it MUST have at least an action parameter for the request which would
# be in kwargs if it's using the old mode.
if kwargs:
- if parameters is not self._PARAM_DEFAULT:
+ if parameters is not self.PARAM_DEFAULT:
# 'parameters' AND kwargs is set. In that case think of
# 'parameters' being an old kwarg which is now filled in an
# actual parameter
@@ -234,7 +235,7 @@
# When parameters wasn't set it's likely that kwargs-mode was used
self._warn_kwargs()
parameters = kwargs
- elif parameters is self._PARAM_DEFAULT:
+ elif parameters is self.PARAM_DEFAULT:
parameters = {}
self._params: dict[str, Any] = {}
if 'action' not in parameters:
diff --git a/tests/aspects.py b/tests/aspects.py
index 1649627..f2945f1 100644
--- a/tests/aspects.py
+++ b/tests/aspects.py
@@ -22,11 +22,11 @@
from contextlib import contextmanager, suppress
from functools import wraps
from http import HTTPStatus
-from typing import Any
from unittest.util import safe_repr
import pywikibot
from pywikibot import Site, config
+from pywikibot.backports import sentinel
from pywikibot.comms import http
from pywikibot.data.api import Request as _original_Request
from pywikibot.exceptions import (
@@ -1555,9 +1555,9 @@
]
# Require no instead string
- NO_INSTEAD = object()
+ NO_INSTEAD = sentinel('NO_INSTEAD')
# Require an instead string
- INSTEAD = object()
+ INSTEAD = sentinel('INSTEAD')
def __init__(self, *args, **kwargs) -> None:
"""Initializer."""
@@ -1587,7 +1587,7 @@
@classmethod
def _build_message(cls,
deprecated: str | None,
- instead: str | bool | None) -> Any:
+ instead: str | bool | None) -> str | None | sentinel:
"""Build a deprecation warning result.
.. version-changed:: 9.3
@@ -1628,13 +1628,12 @@
"""
self.assertDeprecation(self._build_message(deprecated, instead))
- def assertDeprecation(self, msg=None) -> None:
+ def assertDeprecation(self, msg: str | None | sentinel = None) -> None:
"""Assert that a deprecation warning happened.
:param msg: Either the specific message or None to allow any generic
message. When set to ``INSTEAD`` it only counts those supplying an
alternative and when ``NO_INSTEAD`` only those not supplying one.
- :type msg: str or None or INSTEAD or NO_INSTEAD
"""
if msg is None or msg is self.INSTEAD or msg is self.NO_INSTEAD:
deprecation_messages = self.deprecation_messages
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1310525?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: I730359f0a4862dc61ca1a8107aa4a22609d1718b
Gerrit-Change-Number: 1310525
Gerrit-PatchSet: 3
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/+/1310532?usp=email )
Change subject: IMPR: Use JSONDecodeError instead of generic ValueError in api.Requests
......................................................................
IMPR: Use JSONDecodeError instead of generic ValueError in api.Requests
requests.exceptions.JSONDecodeError is a subclass of ValueError.
Anyway using ValueError in api.Requests._json_loads might be to broad;
use requests.exceptions.JSONDecodeError instead.
Change-Id: I0a4ad4412252ab809f979aca361ffa5943426f57
---
M pywikibot/data/api/_requests.py
1 file changed, 9 insertions(+), 10 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 129f49e..5c5deda 100644
--- a/pywikibot/data/api/_requests.py
+++ b/pywikibot/data/api/_requests.py
@@ -20,10 +20,12 @@
from contextlib import suppress
from email.mime.nonmultipart import MIMENonMultipart
from pathlib import Path
-from typing import TYPE_CHECKING, Any, NoReturn
+from typing import Any, NoReturn
from urllib.parse import unquote, urlencode
from warnings import warn
+import requests
+
import pywikibot
from pywikibot import config
from pywikibot.comms import http
@@ -42,9 +44,6 @@
from pywikibot.tools import deprecated
-if TYPE_CHECKING:
- import requests
-
__all__ = ('CachedRequest', 'Request', 'encode_url')
TEST_RUNNING = os.environ.get('PYWIKIBOT_TEST_RUNNING', '0') == '1'
@@ -773,27 +772,27 @@
self.wait()
return None, use_get
- def _json_loads(self, response) -> dict | None:
+ def _json_loads(self, response: requests.Response) -> dict | None:
"""Return a dict from requests.Response.
.. version-changed:: 8.2
show a warning to add a :meth:`protocol()
<family.Family.protocol>` method to the family file if suitable.
- .. version-changed:: 11.0
+ .. version-removed:: 11.0
The warning about missing or wrong ``protocol()`` method
introduced in version 8.2 was removed.
:param response: a requests.Response object
- :type response: requests.Response
:return: a data dict
- :raises pywikibot.exceptions.APIError: unknown action found
- :raises pywikibot.exceptions.APIError: unknown query result type
+ :raises SiteDefinitionError: Invalid :class:`family.AutoFamily`
+ :raises pywikibot.exceptions.APIError: unknown action found or
+ unknown query result type
:meta public:
"""
try:
result = response.json()
- except ValueError:
+ except requests.exceptions.JSONDecodeError:
# if the result isn't valid JSON, there may be a server problem.
# Wait a few seconds and try again.
# Show 20 lines of bare text without script parts
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1310532?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: I0a4ad4412252ab809f979aca361ffa5943426f57
Gerrit-Change-Number: 1310532
Gerrit-PatchSet: 3
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/+/1312275?usp=email )
Change subject: make_dist: do not check for build/twinw modules if -clear option is used
......................................................................
make_dist: do not check for build/twinw modules if -clear option is used
Change-Id: I49ac58d5a49d2c30d2c389f892a6eceeb30decfb
---
M make_dist.py
1 file changed, 3 insertions(+), 5 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/make_dist.py b/make_dist.py
index b7ab1f4..4a0fd4c 100755
--- a/make_dist.py
+++ b/make_dist.py
@@ -142,11 +142,9 @@
:return: True if no error occurs, else False
"""
- tools = (
- ('build', MODULE),
- ('pyclean', COMMAND),
- ('twine', MODULE),
- )
+ tools = (('pyclean', COMMAND), )
+ if not self.clear:
+ tools += ('build', MODULE), ('twine', MODULE)
for tool, tool_type in tools:
if not self._check_module(tool, tool_type):
if not self.upgrade:
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1312275?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: I49ac58d5a49d2c30d2c389f892a6eceeb30decfb
Gerrit-Change-Number: 1312275
Gerrit-PatchSet: 4
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/+/1312261?usp=email )
Change subject: [fix] Use i18n._altlang for Accept-Language in weblinkchecker.py
......................................................................
[fix] Use i18n._altlang for Accept-Language in weblinkchecker.py
The Accept-Language header sent when checking external links was
hardcoded to prefer German, regardless of which wiki the bot was
running on. This built the header dynamically instead: the site's
own language first, then known fallbacks via i18n._altlang(), then
English, with decreasing quality values.
Tested with 'ru' (no fallback, just adds English) and 'bar'
(correctly falls back to 'de' before English).
Bug: T417572
Change-Id: Iea819c7dbda85f108fc9c2eb0d093c79fcd822bd
---
M scripts/weblinkchecker.py
1 file changed, 12 insertions(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/weblinkchecker.py b/scripts/weblinkchecker.py
index 2fd637c..3193611 100755
--- a/scripts/weblinkchecker.py
+++ b/scripts/weblinkchecker.py
@@ -251,10 +251,21 @@
self.history = history
# use preferred site encodings
encodings = ','.join(self.page.site.encodings())
+
+ # build Accept-Language header: site language first, then its
+ # known fallback languages, then English, each with a
+ # decreasing quality value
+ lang = self.page.site.lang
+ langs = [lang, *i18n._altlang(lang), 'en']
+ accept_language = ','.join(
+ code if i == 0 else f'{code};q={max(0.1, 1 - i * 0.2):.1f}'
+ for i, code in enumerate(langs)
+ )
+
self.header = {
'Accept': 'text/xml,application/xml,application/xhtml+xml,'
'text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
- 'Accept-Language': 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3',
+ 'Accept-Language': accept_language,
'Accept-Charset': f'{encodings};q=0.8,*;q=0.7',
'Keep-Alive': '30',
'Connection': 'keep-alive',
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1312261?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: Iea819c7dbda85f108fc9c2eb0d093c79fcd822bd
Gerrit-Change-Number: 1312261
Gerrit-PatchSet: 3
Gerrit-Owner: Nihar_Chakravarti <niharchakravarti05(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/+/1312276?usp=email )
Change subject: tests: make test_groupnames more robust
......................................................................
tests: make test_groupnames more robust
the defaultdict class might create a default '' value;
take this into account for the test.
Change-Id: I19a3de797265ec026d0decc7622e2995a25ba6fc
---
M tests/i18n_tests.py
1 file changed, 1 insertion(+), 0 deletions(-)
Approvals:
Xqt: Verified; Looks good to me, approved
diff --git a/tests/i18n_tests.py b/tests/i18n_tests.py
index 8066b42..cbb9a8e 100755
--- a/tests/i18n_tests.py
+++ b/tests/i18n_tests.py
@@ -40,6 +40,7 @@
def test_groupnames(self):
"""Test that groupnames are in groups."""
groupnames = set(i18n._LANG_TO_GROUP_NAME.values())
+ groupnames.discard('') # might be created by defaultdict
self.assertLess(groupnames, i18n._LANG_TO_GROUP_NAME.keys())
groups = list(i18n._GROUP_NAME_TO_FALLBACKS)
groups.remove('') # remove empty fallback
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1312276?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: I19a3de797265ec026d0decc7622e2995a25ba6fc
Gerrit-Change-Number: 1312276
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot