From 65170f4a2ef8dc81d3678624ac2a4610d1c6045e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Jim=C3=A9nez=20L=C3=B3pez?= Date: Sun, 8 Sep 2024 21:08:38 -0600 Subject: [PATCH] Add stubs for `python-http-client` (#12626) --- pyrightconfig.stricter.json | 1 + .../@tests/stubtest_allowlist.txt | 1 + stubs/python-http-client/METADATA.toml | 2 ++ .../python_http_client/__init__.pyi | 20 ++++++++++++ .../python_http_client/client.pyi | 31 +++++++++++++++++++ .../python_http_client/exceptions.pyi | 28 +++++++++++++++++ 6 files changed, 83 insertions(+) create mode 100644 stubs/python-http-client/@tests/stubtest_allowlist.txt create mode 100644 stubs/python-http-client/METADATA.toml create mode 100644 stubs/python-http-client/python_http_client/__init__.pyi create mode 100644 stubs/python-http-client/python_http_client/client.pyi create mode 100644 stubs/python-http-client/python_http_client/exceptions.pyi diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index 71fd7855e..05e645583 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -82,6 +82,7 @@ "stubs/PyMySQL", "stubs/python-crontab", "stubs/python-dateutil", + "stubs/python-http-client", "stubs/python-jose", "stubs/pywin32", "stubs/pyxdg", diff --git a/stubs/python-http-client/@tests/stubtest_allowlist.txt b/stubs/python-http-client/@tests/stubtest_allowlist.txt new file mode 100644 index 000000000..f1c4ead36 --- /dev/null +++ b/stubs/python-http-client/@tests/stubtest_allowlist.txt @@ -0,0 +1 @@ +python_http_client.version_file diff --git a/stubs/python-http-client/METADATA.toml b/stubs/python-http-client/METADATA.toml new file mode 100644 index 000000000..73ce01ef6 --- /dev/null +++ b/stubs/python-http-client/METADATA.toml @@ -0,0 +1,2 @@ +version = "3.3.7" +upstream_repository = "https://github.com/sendgrid/python-http-client" diff --git a/stubs/python-http-client/python_http_client/__init__.pyi b/stubs/python-http-client/python_http_client/__init__.pyi new file mode 100644 index 000000000..1c17420c7 --- /dev/null +++ b/stubs/python-http-client/python_http_client/__init__.pyi @@ -0,0 +1,20 @@ +from typing import Final + +from .client import Client as Client +from .exceptions import ( + BadRequestsError as BadRequestsError, + ForbiddenError as ForbiddenError, + GatewayTimeoutError as GatewayTimeoutError, + HTTPError as HTTPError, + InternalServerError as InternalServerError, + MethodNotAllowedError as MethodNotAllowedError, + NotFoundError as NotFoundError, + PayloadTooLargeError as PayloadTooLargeError, + ServiceUnavailableError as ServiceUnavailableError, + TooManyRequestsError as TooManyRequestsError, + UnauthorizedError as UnauthorizedError, + UnsupportedMediaTypeError as UnsupportedMediaTypeError, +) + +dir_path: Final[str] +__version__: Final[str] diff --git a/stubs/python-http-client/python_http_client/client.pyi b/stubs/python-http-client/python_http_client/client.pyi new file mode 100644 index 000000000..f47cebc70 --- /dev/null +++ b/stubs/python-http-client/python_http_client/client.pyi @@ -0,0 +1,31 @@ +from email.message import Message +from typing import Final + +class Response: + def __init__(self, response) -> None: ... + @property + def status_code(self) -> int: ... + @property + def body(self): ... + @property + def headers(self) -> Message: ... + @property + def to_dict(self): ... + +class Client: + methods: Final[set[str]] + host: str + request_headers: dict[str, str] + append_slash: bool + timeout: int + def __init__( + self, + host: str, + request_headers: dict[str, str] | None = None, + version: int | None = None, + url_path: list[str] | None = None, + append_slash: bool = False, + timeout: int | None = None, + ) -> None: ... + def _(self, name: str) -> Client: ... + def __getattr__(self, name: str) -> Client | Response: ... diff --git a/stubs/python-http-client/python_http_client/exceptions.pyi b/stubs/python-http-client/python_http_client/exceptions.pyi new file mode 100644 index 000000000..4852c02d6 --- /dev/null +++ b/stubs/python-http-client/python_http_client/exceptions.pyi @@ -0,0 +1,28 @@ +from email.message import Message +from typing import Final + +class HTTPError(Exception): + status_code: int + reason: str + body: str + headers: Message + def __init__(self, *args) -> None: ... + def __reduce__(self): ... + @property + def to_dict(self): ... + +class BadRequestsError(HTTPError): ... +class UnauthorizedError(HTTPError): ... +class ForbiddenError(HTTPError): ... +class NotFoundError(HTTPError): ... +class MethodNotAllowedError(HTTPError): ... +class PayloadTooLargeError(HTTPError): ... +class UnsupportedMediaTypeError(HTTPError): ... +class TooManyRequestsError(HTTPError): ... +class InternalServerError(HTTPError): ... +class ServiceUnavailableError(HTTPError): ... +class GatewayTimeoutError(HTTPError): ... + +err_dict: Final[dict[int, type[HTTPError]]] + +def handle_error(error) -> HTTPError: ...