Skip to content

Commit 37cbe71

Browse files
Fix httpretty stubs: import Final/aliases and address review
Import Final and define _HTTPMethod/_WritableFileobj so mypy/stubtest pass; apply reviewer suggestions for Protocols and comments. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent ad3d182 commit 37cbe71

4 files changed

Lines changed: 18 additions & 6 deletions

File tree

stubs/httpretty/httpretty/__init__.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Final
2+
13
from .core import (
24
EmptyRequestHeaders as EmptyRequestHeaders,
35
Entry as Entry,
@@ -13,7 +15,7 @@ from .core import (
1315
)
1416
from .errors import HTTPrettyError as HTTPrettyError, UnmockedError as UnmockedError
1517

16-
__version__: str
18+
__version__: Final[str]
1719
HTTPretty = httpretty
1820
activate = httprettified
1921
enabled = httprettized

stubs/httpretty/httpretty/core.pyi

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@ from collections.abc import Callable, Iterable, Mapping
33
from contextlib import AbstractContextManager
44
from http.client import HTTPMessage
55
from types import TracebackType
6-
from typing import Any, Literal, TypeAlias, overload
6+
from typing import Any, Final, Protocol, TypeAlias, overload, type_check_only
77
from typing_extensions import ParamSpec
88

9-
from .http import HttpBaseClass
9+
from .http import HttpBaseClass, _HTTPMethod
1010

1111
_P = ParamSpec("_P")
12-
_HTTPMethod: TypeAlias = Literal["GET", "PUT", "POST", "DELETE", "HEAD", "PATCH", "OPTIONS", "CONNECT"]
12+
13+
@type_check_only
14+
class _WritableFileobj(Protocol):
15+
def write(self, b: bytes, /) -> object: ...
16+
def seek(self, offset: int, /) -> object: ...
17+
1318
_URI: TypeAlias = str | re.Pattern[str]
1419
_HeaderValue: TypeAlias = str | int | bool | None
1520
_Headers: TypeAlias = Mapping[str, _HeaderValue]
@@ -44,7 +49,7 @@ class HTTPrettyRequest(HttpBaseClass):
4449
@property
4550
def host(self) -> str: ...
4651
def parse_querystring(self, qs: str) -> dict[str, list[str]]: ...
47-
def parse_request_body(self, body: str) -> Any: ...
52+
def parse_request_body(self, body: str) -> Any: ... # Any object can be returned if deserialization is successful
4853

4954
class EmptyRequestHeaders(dict[str, str]): ...
5055

@@ -145,6 +150,7 @@ class httpretty(HttpBaseClass):
145150
encoding: str = "utf-8",
146151
verbose: bool = False,
147152
allow_net_connect: bool = True,
153+
# Passed to urllib3.PoolManager as kwargs, and connection pool's parameters have various types
148154
pool_manager_params: Mapping[str, Any] | None = None,
149155
) -> AbstractContextManager[None]: ...
150156
@classmethod

stubs/httpretty/httpretty/http.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from collections.abc import Sequence
2+
from typing import Final, Literal, TypeAlias
23
from typing_extensions import TypeVar
34

45
_T = TypeVar("_T", str, bytes)
6+
_HTTPMethod: TypeAlias = Literal["GET", "PUT", "POST", "DELETE", "HEAD", "PATCH", "OPTIONS", "CONNECT"]
57

68
STATUSES: dict[int, str]
79

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
version: str
1+
from typing import Final
2+
3+
version: Final[str]

0 commit comments

Comments
 (0)