Add stubs for httpretty - #16048
Conversation
This comment has been minimized.
This comment has been minimized.
donbarbos
left a comment
There was a problem hiding this comment.
Thank you! I noted a few moments:
| @property | ||
| def host(self) -> str: ... | ||
| def parse_querystring(self, qs: str) -> dict[str, list[str]]: ... | ||
| def parse_request_body(self, body: str) -> Any: ... |
There was a problem hiding this comment.
Let's add some explanatory comments:
| def parse_request_body(self, body: str) -> Any: ... | |
| def parse_request_body(self, body: str) -> Any: ... # Any object can be returned if deserialization is successful |
| @@ -0,0 +1 @@ | |||
| version: str | |||
There was a problem hiding this comment.
| version: str | |
| from typing import Final | |
| version: Final[str] |
| ) | ||
| from .errors import HTTPrettyError as HTTPrettyError, UnmockedError as UnmockedError | ||
|
|
||
| __version__: str |
There was a problem hiding this comment.
| __version__: str | |
| __version__: Final[str] |
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Semyon Moroz <donbarbos@proton.me>
Co-authored-by: Semyon Moroz <donbarbos@proton.me>
Co-authored-by: Semyon Moroz <donbarbos@proton.me>
Co-authored-by: Semyon Moroz <donbarbos@proton.me>
Co-authored-by: Semyon Moroz <donbarbos@proton.me>
Co-authored-by: Semyon Moroz <donbarbos@proton.me>
Import Final and define _HTTPMethod/_WritableFileobj so mypy/stubtest pass; apply reviewer suggestions for Protocols and comments. Co-authored-by: Cursor <cursoragent@cursor.com>
f015aa0 to
37cbe71
Compare
HttpBaseClass already marks them Final; subclass overrides fail mypy. Co-authored-by: Cursor <cursoragent@cursor.com>
This comment has been minimized.
This comment has been minimized.
|
Addressed review feedback (Final imports, |
srittau
left a comment
There was a problem hiding this comment.
Thanks. I'm not sure that we need the tests. In typeshed, we only add regression tests for functions and classes which are known to have caused complex problems in the past, or where stubs are difficult to get right. 100% test coverage for typeshed is neither necessary nor desirable, as it would lead to code duplication.
See tests/REGRESSION.md for more information.
A few smaller suggestions below.
| @overload | ||
| def httprettified(test: Callable[_P, Any]) -> Callable[_P, Any]: ... | ||
| @overload | ||
| def httprettified( | ||
| test: None = None, allow_net_connect: bool = True, verbose: bool = False | ||
| ) -> Callable[[Callable[_P, Any]], Callable[_P, Any]]: ... |
There was a problem hiding this comment.
Considering the return value is passed back unchanged:
| @overload | |
| def httprettified(test: Callable[_P, Any]) -> Callable[_P, Any]: ... | |
| @overload | |
| def httprettified( | |
| test: None = None, allow_net_connect: bool = True, verbose: bool = False | |
| ) -> Callable[[Callable[_P, Any]], Callable[_P, Any]]: ... | |
| @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]]: ... |
(Also needs a type var definition _R = TypeVar("_R") at the top of the file.)
| METHODS: tuple[_HTTPMethod, ...] | ||
|
|
||
| def parse_requestline(s: str) -> tuple[str, str, str]: ... | ||
| def last_requestline(sent_data: Sequence[_T]) -> _T | None: ... |
There was a problem hiding this comment.
Since this is sent to reversed, we can use a protocol here:
| def last_requestline(sent_data: Sequence[_T]) -> _T | None: ... | |
| def last_requestline(sent_data: SupportsLenAndGetItem[_T]) -> _T | None: ... |
(SupportsLenAndGetItem needs to be imported from _typeshed.)
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Adds type stubs for HTTPretty 1.1.4.
Related: #16047.