Skip to content

Commit

Permalink
Improvements to type stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Dec 29, 2023
1 parent c06f124 commit b74886d
Show file tree
Hide file tree
Showing 5 changed files with 232 additions and 239 deletions.
12 changes: 6 additions & 6 deletions requests_mock/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Stubs for requests_mock

from requests_mock.adapter import (
ANY as ANY,
Adapter as Adapter,
Callback as Callback,
ANY as ANY,
Adapter as Adapter,
Callback as Callback,
AdditionalMatcher as AdditionalMatcher,
)
from requests_mock.exceptions import (
MockException as MockException,
MockException as MockException,
NoMockAddress as NoMockAddress,
)
from requests_mock.mocker import (
DELETE as DELETE,
GET as GET,
DELETE as DELETE,
GET as GET,
HEAD as HEAD,
Mocker as Mocker,
MockerCore as MockerCore,
Expand Down
55 changes: 28 additions & 27 deletions requests_mock/adapter.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from http.cookiejar import CookieJar
from io import IOBase
from typing import Any, Callable, Dict, List, NewType, Optional, Pattern, Type, TypeVar, Union
from typing import Any, Callable, NewType, Pattern, TypeVar

from requests import Response
from requests.adapters import BaseAdapter
Expand All @@ -15,16 +15,16 @@ AnyMatcher = NewType("AnyMatcher", object)

ANY: AnyMatcher = ...

T = TypeVar('T')
T = TypeVar("T")
Callback = Callable[[Request, Context], T]
Matcher = Callable[[Request], Optional[Response]]
Matcher = Callable[[Request], Response | None]
AdditionalMatcher = Callable[[Request], bool]

class _RequestHistoryTracker:
request_history: List[Request] = ...
request_history: list[Request] = ...
def __init__(self) -> None: ...
@property
def last_request(self) -> Optional[Request]: ...
def last_request(self) -> Request | None: ...
@property
def called(self) -> bool: ...
@property
Expand All @@ -36,38 +36,39 @@ class _RunRealHTTP(Exception): ...

class _Matcher(_RequestHistoryTracker):
def __init__(
self,
method: Any,
url: Any,
responses: Any,
complete_qs: Any,
request_headers: Any,
additional_matcher: AdditionalMatcher,
real_http: Any,
case_sensitive: Any
self,
method: Any,
url: Any,
responses: Any,
complete_qs: Any,
request_headers: Any,
additional_matcher: AdditionalMatcher,
real_http: Any,
case_sensitive: Any,
) -> None: ...
def __call__(self, request: Request) -> Optional[Response]: ...
def __call__(self, request: Request) -> Response | None: ...

class Adapter(BaseAdapter, _RequestHistoryTracker):
def __init__(self, case_sensitive: bool = ...) -> None: ...
def register_uri(
self,
method: Union[str, AnyMatcher],
url: Union[str, Pattern[str], AnyMatcher],
response_list: Optional[List[Dict[str, Any]]] = ...,
method: str | AnyMatcher,
url: str | Pattern[str],
AnyMatcher,
response_list: list[dict[str, Any]] | None = ...,
*,
request_headers: Dict[str, str] = ...,
request_headers: dict[str, str] = ...,
complete_qs: bool = ...,
status_code: int = ...,
reason: str = ...,
headers: Dict[str, str] = ...,
cookies: Union[CookieJar, Dict[str, str]] = ...,
json: Union[Any, Callback[Any]] = ...,
text: Union[str, Callback[str]] = ...,
content: Union[bytes, Callback[bytes]] = ...,
body: Union[IOBase, Callback[IOBase]] = ...,
headers: dict[str, str] = ...,
cookies: CookieJar | dict[str, str] = ...,
json: Any | Callback[Any] = ...,
text: str | Callback[str] = ...,
content: bytes | Callback[bytes] = ...,
body: IOBase | Callback[IOBase] = ...,
raw: HTTPResponse = ...,
exc: Union[Exception, Type[Exception]] = ...,
exc: Exception | type[Exception] = ...,
additional_matcher: AdditionalMatcher = ...,
**kwargs: Any
) -> _Matcher: ...
Expand Down
Loading

0 comments on commit b74886d

Please sign in to comment.