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
pywikibot-commits@lists.wikimedia.org