jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1225073?usp=email )

Change subject: doc: Add typing information and improve docstring for 
Request._http_request
......................................................................

doc: Add typing information and improve docstring for Request._http_request

Change-Id: I6ca773d1984d6df124918b5fd915920ef71bb066
---
M pywikibot/data/api/_requests.py
1 file changed, 36 insertions(+), 4 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 a8289f0..419439e 100644
--- a/pywikibot/data/api/_requests.py
+++ b/pywikibot/data/api/_requests.py
@@ -20,7 +20,7 @@
 from contextlib import suppress
 from email.mime.nonmultipart import MIMENonMultipart
 from pathlib import Path
-from typing import Any, NoReturn
+from typing import TYPE_CHECKING, Any, NoReturn
 from urllib.parse import unquote, urlencode, urlparse
 from warnings import warn

@@ -42,6 +42,9 @@
 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'
@@ -678,9 +681,25 @@
                         f'Headers: {headers!r}\nURI: {uri!r}\nBody: {body!r}')
         return use_get, uri, body, headers

-    def _http_request(self, use_get: bool, uri: str, data, headers,
-                      paramstring) -> tuple:
-        """Get or post a http request with exception handling.
+    def _http_request(
+        self,
+        use_get: bool,
+        uri: str,
+        data: dict[str, str | int | float | bool] | None,
+        headers: dict[str, str] | None,
+        paramstring: str
+    ) -> tuple[requests.Response | None, bool]:
+        """Send an HTTP GET or POST request with exception handling.
+
+        This method wraps :func:`comms.http.request` to send a request
+        to the site's server, handle common HTTP errors, and optionally
+        retry using an alternative scheme or method.
+
+        .. note::
+           ImportError during request handling will terminate the
+           program; it is not propagated as an exception. Any other
+           unexpected exceptions are logged and trigger a wait  before
+           retrying; they are not propagated to the caller.

         .. versionchanged:: 8.2
            change the scheme if the previous request didn't have json
@@ -688,9 +707,22 @@
         .. versionchanged:: 9.2
            no wait cycles for :exc:`ImportError` and :exc:`NameError`.

+        :param use_get: If True, send a GET request; otherwise send POST.
+        :param uri: The URI path to request on the site.
+        :param data: The data to send in the request body (for POST) or
+            query string (for GET).
+        :param headers: HTTP headers to include in the request.
+        :param paramstring: A string representing the request parameters
+            (used for logging/debug).
         :return: a tuple containing requests.Response object from
             :func:`comms.http.request` and *use_get* value

+        :raises Client414Error: If a 414 URI Too Long occurs on a POST
+            request after GET retry failed.
+        :raises ConnectionError: For network connection errors.
+        :raises FatalServerError: For critical server errors.
+        :raises NameError: If a NameError occurs during request handling.
+
         :meta public:
         """
         kwargs = {}

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1225073?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: I6ca773d1984d6df124918b5fd915920ef71bb066
Gerrit-Change-Number: 1225073
Gerrit-PatchSet: 1
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