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 <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to