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 <[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