-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add full request typing signatures for session HTTP methods #8463
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
Changes from 5 commits
680d4f5
9212617
cb998f9
2df4510
c3051af
c8368cf
ac10ab0
3d4155f
e4af6b1
703e89f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Added a 3.11-specific overloads to ``ClientSession`` -- by :user:`max-muoto`. |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -29,9 +29,11 @@ | |||||||||||||||
| Set, | ||||||||||||||||
| Tuple, | ||||||||||||||||
| Type, | ||||||||||||||||
| TypedDict, | ||||||||||||||||
| TypeVar, | ||||||||||||||||
| Union, | ||||||||||||||||
| final, | ||||||||||||||||
| overload, | ||||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
| from multidict import CIMultiDict, MultiDict, MultiDictProxy, istr | ||||||||||||||||
|
|
@@ -150,6 +152,34 @@ | |||||||||||||||
| SSLContext = None | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| class _RequestOptions(TypedDict, total=False): | ||||||||||||||||
Dreamsorcerer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
| params: Union[Mapping[str, str], None] | ||||||||||||||||
| data: Any | ||||||||||||||||
| json: Any | ||||||||||||||||
| cookies: Union[LooseCookies, None] | ||||||||||||||||
| headers: Union[LooseHeaders, None] | ||||||||||||||||
| skip_auto_headers: Union[Iterable[str], None] | ||||||||||||||||
| auth: Union[BasicAuth, None] | ||||||||||||||||
| allow_redirects: bool | ||||||||||||||||
Dreamsorcerer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
| max_redirects: int | ||||||||||||||||
| compress: Union[str, None] | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This contradicts the documentation for aiohttp/docs/client_reference.rst Lines 431 to 434 in 48a5e07
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's copied from _request(), not something related to this PR specifically. Feel free to open a PR to fix it. Looking at the code, it's the docs that are inaccurate, though we could expand the typing to allow bool: aiohttp/aiohttp/client_reqrep.py Lines 434 to 436 in 48a5e07
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, basically:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not entirely clear how the str is used though, I think maybe only deflate and gzip are valid.. |
||||||||||||||||
| chunked: Union[bool, None] | ||||||||||||||||
| expect100: bool | ||||||||||||||||
| raise_for_status: Union[None, bool, Callable[[ClientResponse], Awaitable[None]]] | ||||||||||||||||
| read_until_eof: bool | ||||||||||||||||
| proxy: Union[StrOrURL, None] | ||||||||||||||||
| proxy_auth: Union[BasicAuth, None] | ||||||||||||||||
| timeout: "Union[ClientTimeout, _SENTINEL, None]" | ||||||||||||||||
| ssl: Union[SSLContext, bool, Fingerprint] | ||||||||||||||||
| server_hostname: Union[str, None] | ||||||||||||||||
| proxy_headers: Union[LooseHeaders, None] | ||||||||||||||||
| trace_request_ctx: Union[SimpleNamespace, None] | ||||||||||||||||
| read_bufsize: Union[int, None] | ||||||||||||||||
| auto_decompress: Union[bool, None] | ||||||||||||||||
| max_line_size: Union[int, None] | ||||||||||||||||
| max_field_size: Union[int, None] | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| @dataclasses.dataclass(frozen=True) | ||||||||||||||||
| class ClientTimeout: | ||||||||||||||||
| total: Optional[float] = None | ||||||||||||||||
|
|
@@ -187,6 +217,44 @@ class ClientTimeout: | |||||||||||||||
| class ClientSession: | ||||||||||||||||
| """First-class interface for making HTTP requests.""" | ||||||||||||||||
|
|
||||||||||||||||
| if sys.version_info >= (3, 11): | ||||||||||||||||
Dreamsorcerer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||
| from typing import Unpack | ||||||||||||||||
|
|
||||||||||||||||
| @overload | ||||||||||||||||
| def get( | ||||||||||||||||
| self, | ||||||||||||||||
| url: StrOrURL, | ||||||||||||||||
| **kwargs: Unpack["_RequestOptions"], | ||||||||||||||||
| ) -> "_RequestContextManager": ... | ||||||||||||||||
|
||||||||||||||||
|
|
||||||||||||||||
| @overload | ||||||||||||||||
| def put( | ||||||||||||||||
| self, | ||||||||||||||||
| url: StrOrURL, | ||||||||||||||||
| **kwargs: Unpack["_RequestOptions"], | ||||||||||||||||
| ) -> "_RequestContextManager": ... | ||||||||||||||||
|
||||||||||||||||
|
|
||||||||||||||||
| @overload | ||||||||||||||||
| def post( | ||||||||||||||||
| self, | ||||||||||||||||
| url: StrOrURL, | ||||||||||||||||
| **kwargs: Unpack["_RequestOptions"], | ||||||||||||||||
| ) -> "_RequestContextManager": ... | ||||||||||||||||
|
||||||||||||||||
|
|
||||||||||||||||
| @overload | ||||||||||||||||
| def delete( | ||||||||||||||||
| self, | ||||||||||||||||
| url: StrOrURL, | ||||||||||||||||
| **kwargs: Unpack["_RequestOptions"], | ||||||||||||||||
| ) -> "_RequestContextManager": ... | ||||||||||||||||
|
||||||||||||||||
|
|
||||||||||||||||
| @overload | ||||||||||||||||
| def head( | ||||||||||||||||
| self, | ||||||||||||||||
| url: StrOrURL, | ||||||||||||||||
| **kwargs: Unpack["_RequestOptions"], | ||||||||||||||||
| ) -> "_RequestContextManager": ... | ||||||||||||||||
|
||||||||||||||||
|
|
||||||||||||||||
| __slots__ = ( | ||||||||||||||||
| "_base_url", | ||||||||||||||||
| "_source_traceback", | ||||||||||||||||
|
|
||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.