-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add stubs for httpretty #16048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
srittau
merged 14 commits into
python:main
from
adamtheturtle:agent/add-httpretty-stubs
Aug 20, 2026
Merged
Add stubs for httpretty #16048
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7f21c4c
Add stubs for HTTPretty
adamtheturtle 98a97ec
Update stubs/httpretty/httpretty/__init__.pyi\
adamtheturtle 1f0d5e0
Update stubs/httpretty/httpretty/core.pyi
adamtheturtle 68595b7
Update stubs/httpretty/httpretty/http.pyi
adamtheturtle a92d182
Update stubs/httpretty/httpretty/http.pyi
adamtheturtle f4ffa52
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] c530889
Update stubs/httpretty/httpretty/core.pyi
adamtheturtle e955950
Update stubs/httpretty/httpretty/core.pyi
adamtheturtle ad3d182
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 37cbe71
Fix httpretty stubs: import Final/aliases and address review
adamtheturtle 254b997
Avoid redeclaring Final HTTP method attrs on httpretty
adamtheturtle d767b45
Remove unnecessary httpretty regression tests
adamtheturtle a0a55f0
Preserve return type in httprettified
adamtheturtle c267ac4
Accept reversible data in last_requestline
adamtheturtle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| version = "1.1.4" | ||
| upstream-repository = "https://github.com/gabrielfalcao/HTTPretty" | ||
| partial-stub = true | ||
|
|
||
| [tool.stubtest] | ||
| ignore-missing-stub = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| from typing import Final | ||
|
|
||
| from .core import ( | ||
| EmptyRequestHeaders as EmptyRequestHeaders, | ||
| Entry as Entry, | ||
| HTTPrettyRequest as HTTPrettyRequest, | ||
| HTTPrettyRequestEmpty as HTTPrettyRequestEmpty, | ||
| URIInfo as URIInfo, | ||
| URIMatcher as URIMatcher, | ||
| get_default_thread_timeout as get_default_thread_timeout, | ||
| httprettified as httprettified, | ||
| httprettized as httprettized, | ||
| httpretty as httpretty, | ||
| set_default_thread_timeout as set_default_thread_timeout, | ||
| ) | ||
| from .errors import HTTPrettyError as HTTPrettyError, UnmockedError as UnmockedError | ||
|
|
||
| __version__: Final[str] | ||
| HTTPretty = httpretty | ||
| activate = httprettified | ||
| enabled = httprettized | ||
| enable = httpretty.enable | ||
| register_uri = httpretty.register_uri | ||
| disable = httpretty.disable | ||
| is_enabled = httpretty.is_enabled | ||
| reset = httpretty.reset | ||
| Response = httpretty.Response | ||
| GET: Final = "GET" | ||
| PUT: Final = "PUT" | ||
| POST: Final = "POST" | ||
| DELETE: Final = "DELETE" | ||
| HEAD: Final = "HEAD" | ||
| PATCH: Final = "PATCH" | ||
| OPTIONS: Final = "OPTIONS" | ||
| CONNECT: Final = "CONNECT" | ||
|
|
||
| def last_request() -> HTTPrettyRequest | HTTPrettyRequestEmpty: ... | ||
| def latest_requests() -> list[HTTPrettyRequest]: ... | ||
| def has_request() -> bool: ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| from typing import TypeVar | ||
|
|
||
| _T = TypeVar("_T") | ||
|
|
||
| class BaseClass: ... | ||
|
|
||
| def encode_obj(in_obj: _T) -> _T: ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,202 @@ | ||
| import re | ||
| from collections.abc import Callable, Iterable, Mapping | ||
| from contextlib import AbstractContextManager | ||
| from http.client import HTTPMessage | ||
| from types import TracebackType | ||
| from typing import Any, Protocol, TypeAlias, overload, type_check_only | ||
| from typing_extensions import ParamSpec, TypeVar | ||
|
|
||
| from .http import HttpBaseClass, _HTTPMethod | ||
|
|
||
| _P = ParamSpec("_P") | ||
| _R = TypeVar("_R") | ||
|
|
||
| @type_check_only | ||
| class _WritableFileobj(Protocol): | ||
| def write(self, b: bytes, /) -> object: ... | ||
| def seek(self, offset: int, /) -> object: ... | ||
|
|
||
| _URI: TypeAlias = str | re.Pattern[str] | ||
| _HeaderValue: TypeAlias = str | int | bool | None | ||
| _Headers: TypeAlias = Mapping[str, _HeaderValue] | ||
| _Body: TypeAlias = str | bytes | ||
| _ResponseBody: TypeAlias = _Body | Callable[[HTTPrettyRequest, str, _Headers], tuple[int, _Headers, _Body]] | ||
|
|
||
| def set_default_thread_timeout(timeout: float) -> None: ... | ||
| def get_default_thread_timeout() -> float: ... | ||
|
|
||
| class HTTPrettyRequest(HttpBaseClass): | ||
| headers: HTTPMessage | ||
| raw_headers: str | ||
| path: str | ||
| querystring: dict[str, list[str]] | ||
| parsed_body: Any # It can be any object after parsing raw (str) body | ||
| created_at: float | ||
| def __init__( | ||
| self, headers: str | bytes, body: _Body = "", sock: object | None = None, path_encoding: str = "iso-8859-1" | ||
| ) -> None: ... | ||
| @property | ||
| def method(self) -> str: ... | ||
| @property | ||
| def protocol(self) -> str: ... | ||
|
|
||
| @property | ||
| def body(self) -> str: ... | ||
| @body.setter | ||
| def body(self, value: _Body) -> None: ... | ||
|
|
||
| @property | ||
| def url(self) -> str: ... | ||
| @property | ||
| def host(self) -> str: ... | ||
| def parse_querystring(self, qs: str) -> dict[str, list[str]]: ... | ||
| def parse_request_body(self, body: str) -> Any: ... # Any object can be returned if deserialization is successful | ||
|
|
||
| class EmptyRequestHeaders(dict[str, str]): ... | ||
|
|
||
| class HTTPrettyRequestEmpty: | ||
| method: str | None | ||
| url: str | None | ||
| body: str | ||
| headers: EmptyRequestHeaders | ||
|
|
||
| class Entry(HttpBaseClass): | ||
| method: _HTTPMethod | ||
| uri: str | ||
| request: HTTPrettyRequest | ||
| body: _Body | ||
| status: int | ||
| streaming: bool | ||
| adding_headers: dict[str, str] | ||
| forcing_headers: dict[str, str] | ||
| def __init__( | ||
| self, | ||
| method: str, | ||
| uri: str, | ||
| body: _ResponseBody, | ||
| adding_headers: _Headers | None = None, | ||
| forcing_headers: _Headers | None = None, | ||
| status: int = 200, | ||
| streaming: bool = False, | ||
| **headers: str, | ||
| ) -> None: ... | ||
| def validate(self) -> None: ... | ||
| def normalize_headers(self, headers: _Headers) -> dict[str, str]: ... | ||
| def fill_filekind(self, fk: _WritableFileobj) -> None: ... | ||
|
|
||
| class URIInfo(HttpBaseClass): | ||
| default_str_attrs: tuple[str, ...] | ||
| username: str | ||
| password: str | ||
| hostname: str | ||
| port: int | ||
| path: str | ||
| query: str | ||
| scheme: str | ||
| fragment: str | ||
| last_request: HTTPrettyRequest | None | ||
| def __init__( | ||
| self, | ||
| username: str = "", | ||
| password: str = "", | ||
| hostname: str = "", | ||
| port: int = 80, | ||
| path: str = "/", | ||
| query: str = "", | ||
| fragment: str = "", | ||
| scheme: str = "", | ||
| last_request: HTTPrettyRequest | None = None, | ||
| ) -> None: ... | ||
| def to_str(self, attrs: Iterable[str]) -> str: ... | ||
| def str_with_query(self) -> str: ... | ||
| def full_url(self, use_querystring: bool = True) -> str: ... | ||
| def get_full_domain(self) -> str: ... | ||
| @classmethod | ||
| def from_uri(cls, uri: str, entry: Entry) -> URIInfo: ... | ||
|
|
||
| class URIMatcher: | ||
| regex: re.Pattern[str] | None | ||
| info: URIInfo | None | ||
| entries: list[Entry] | ||
| priority: int | ||
| uri: _URI | ||
| def __init__(self, uri: _URI, entries: Iterable[Entry], match_querystring: bool = False, priority: int = 0) -> None: ... | ||
| def matches(self, info: URIInfo) -> bool: ... | ||
| def get_next_entry(self, method: _HTTPMethod, info: URIInfo, request: HTTPrettyRequest) -> Entry: ... | ||
|
|
||
| class httpretty(HttpBaseClass): | ||
| METHODS: tuple[_HTTPMethod, ...] | ||
| latest_requests: list[HTTPrettyRequest] | ||
| last_request: HTTPrettyRequest | HTTPrettyRequestEmpty | ||
| allow_net_connect: bool | ||
| @classmethod | ||
| def match_uriinfo(cls, info: URIInfo) -> tuple[Entry | None, list[str]]: ... | ||
| @classmethod | ||
| def match_https_hostname(cls, hostname: str) -> bool: ... | ||
| @classmethod | ||
| def match_http_address(cls, hostname: str, port: int) -> bool: ... | ||
| @classmethod | ||
| def record( | ||
| cls, | ||
| filename: str, | ||
| indentation: int = 4, | ||
| encoding: str = "utf-8", | ||
| verbose: bool = False, | ||
| allow_net_connect: bool = True, | ||
| # Passed to urllib3.PoolManager as kwargs, and connection pool's parameters have various types | ||
| pool_manager_params: Mapping[str, Any] | None = None, | ||
| ) -> AbstractContextManager[None]: ... | ||
| @classmethod | ||
| def playback(cls, filename: str, allow_net_connect: bool = True, verbose: bool = False) -> AbstractContextManager[None]: ... | ||
| @classmethod | ||
| def reset(cls) -> None: ... | ||
| @classmethod | ||
| def historify_request(cls, headers: str | bytes, body: _Body = "", sock: object | None = None) -> HTTPrettyRequest: ... | ||
| @classmethod | ||
| def register_uri( | ||
| cls, | ||
| method: str, | ||
| uri: _URI, | ||
| body: _ResponseBody = '{"message": "HTTPretty :)"}', | ||
| adding_headers: _Headers | None = None, | ||
| forcing_headers: _Headers | None = None, | ||
| status: int = 200, | ||
| responses: Iterable[Entry] | None = None, | ||
| match_querystring: bool = False, | ||
| priority: int = 0, | ||
| **headers: str, | ||
| ) -> None: ... | ||
| @classmethod | ||
| def Response( | ||
| cls, | ||
| body: _ResponseBody, | ||
| method: _HTTPMethod | None = None, | ||
| uri: str | None = None, | ||
| adding_headers: _Headers | None = None, | ||
| forcing_headers: _Headers | None = None, | ||
| status: int = 200, | ||
| streaming: bool = False, | ||
| **headers: str, | ||
| ) -> Entry: ... | ||
| @classmethod | ||
| def disable(cls) -> None: ... | ||
| @classmethod | ||
| def is_enabled(cls) -> bool: ... | ||
| @classmethod | ||
| def enable(cls, allow_net_connect: bool = True, verbose: bool = False) -> None: ... | ||
|
|
||
| class httprettized: | ||
| allow_net_connect: bool | ||
| verbose: bool | ||
| def __init__(self, allow_net_connect: bool = True, verbose: bool = False) -> None: ... | ||
| def __enter__(self) -> None: ... | ||
| def __exit__( | ||
| self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None | ||
| ) -> None: ... | ||
|
|
||
| @overload | ||
| def httprettified(test: Callable[_P, _R]) -> Callable[_P, _R]: ... | ||
| @overload | ||
| def httprettified( | ||
| test: None = None, allow_net_connect: bool = True, verbose: bool = False | ||
| ) -> Callable[[Callable[_P, _R]], Callable[_P, _R]]: ... | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| class HTTPrettyError(Exception): ... | ||
|
|
||
| class UnmockedError(HTTPrettyError): | ||
| def __init__(self, message: str = ..., request: object | None = None, address: object | None = None) -> None: ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| from _typeshed import SupportsLenAndGetItem | ||
| from typing import Final, Literal, TypeAlias | ||
| from typing_extensions import TypeVar | ||
|
|
||
| _T = TypeVar("_T", str, bytes) | ||
| _HTTPMethod: TypeAlias = Literal["GET", "PUT", "POST", "DELETE", "HEAD", "PATCH", "OPTIONS", "CONNECT"] | ||
|
|
||
| STATUSES: dict[int, str] | ||
|
|
||
| class HttpBaseClass: | ||
| GET: Final = "GET" | ||
| PUT: Final = "PUT" | ||
| POST: Final = "POST" | ||
| DELETE: Final = "DELETE" | ||
| HEAD: Final = "HEAD" | ||
| PATCH: Final = "PATCH" | ||
| OPTIONS: Final = "OPTIONS" | ||
| CONNECT: Final = "CONNECT" | ||
| METHODS: tuple[_HTTPMethod, ...] | ||
|
|
||
| def parse_requestline(s: str) -> tuple[str, str, str]: ... | ||
| def last_requestline(sent_data: SupportsLenAndGetItem[_T]) -> _T | None: ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| def utf8(s: str | bytes) -> bytes: ... | ||
| def decode_utf8(s: str | bytes) -> str: ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from typing import Final | ||
|
|
||
| version: Final[str] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.