-
-
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 6 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 | ||||||||||||||||
|
|
@@ -986,61 +1016,112 @@ def _prepare_headers(self, headers: Optional[LooseHeaders]) -> "CIMultiDict[str] | |||||||||||||||
| added_names.add(key) | ||||||||||||||||
| return result | ||||||||||||||||
|
|
||||||||||||||||
| def get( | ||||||||||||||||
| self, url: StrOrURL, *, allow_redirects: bool = True, **kwargs: Any | ||||||||||||||||
| ) -> "_RequestContextManager": | ||||||||||||||||
| """Perform HTTP GET request.""" | ||||||||||||||||
| return _RequestContextManager( | ||||||||||||||||
| self._request(hdrs.METH_GET, url, allow_redirects=allow_redirects, **kwargs) | ||||||||||||||||
| ) | ||||||||||||||||
| if sys.version_info >= (3, 11) and TYPE_CHECKING: | ||||||||||||||||
| import typing | ||||||||||||||||
Dreamsorcerer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||
|
|
||||||||||||||||
| def get( | ||||||||||||||||
| self, | ||||||||||||||||
| url: StrOrURL, | ||||||||||||||||
| **kwargs: typing.Unpack[_RequestOptions], | ||||||||||||||||
| ) -> "_RequestContextManager": ... | ||||||||||||||||
|
||||||||||||||||
|
|
||||||||||||||||
| def options( | ||||||||||||||||
| self, | ||||||||||||||||
| url: StrOrURL, | ||||||||||||||||
| **kwargs: typing.Unpack[_RequestOptions], | ||||||||||||||||
| ) -> "_RequestContextManager": ... | ||||||||||||||||
|
||||||||||||||||
|
|
||||||||||||||||
| def head( | ||||||||||||||||
| self, | ||||||||||||||||
| url: StrOrURL, | ||||||||||||||||
| **kwargs: typing.Unpack[_RequestOptions], | ||||||||||||||||
| ) -> "_RequestContextManager": ... | ||||||||||||||||
|
||||||||||||||||
|
|
||||||||||||||||
| def post( | ||||||||||||||||
| self, | ||||||||||||||||
| url: StrOrURL, | ||||||||||||||||
| **kwargs: typing.Unpack[_RequestOptions], | ||||||||||||||||
| ) -> "_RequestContextManager": ... | ||||||||||||||||
|
||||||||||||||||
|
|
||||||||||||||||
| def put( | ||||||||||||||||
| self, | ||||||||||||||||
| url: StrOrURL, | ||||||||||||||||
| **kwargs: typing.Unpack[_RequestOptions], | ||||||||||||||||
| ) -> "_RequestContextManager": ... | ||||||||||||||||
|
||||||||||||||||
|
|
||||||||||||||||
| def patch( | ||||||||||||||||
| self, | ||||||||||||||||
| url: StrOrURL, | ||||||||||||||||
| **kwargs: typing.Unpack[_RequestOptions], | ||||||||||||||||
| ) -> "_RequestContextManager": ... | ||||||||||||||||
|
||||||||||||||||
|
|
||||||||||||||||
| def delete( | ||||||||||||||||
| self, | ||||||||||||||||
| url: StrOrURL, | ||||||||||||||||
| **kwargs: typing.Unpack[_RequestOptions], | ||||||||||||||||
| ) -> "_RequestContextManager": ... | ||||||||||||||||
Check noticeCode scanning / CodeQL Statement has no effect
This statement has no effect.
|
||||||||||||||||
|
|
||||||||||||||||
| else: | ||||||||||||||||
|
|
||||||||||||||||
| def get( | ||||||||||||||||
| self, url: StrOrURL, *, allow_redirects: bool = True, **kwargs: Any | ||||||||||||||||
| ) -> "_RequestContextManager": | ||||||||||||||||
| """Perform HTTP GET request.""" | ||||||||||||||||
| return _RequestContextManager( | ||||||||||||||||
| self._request( | ||||||||||||||||
| hdrs.METH_GET, url, allow_redirects=allow_redirects, **kwargs | ||||||||||||||||
| ) | ||||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
| def options( | ||||||||||||||||
| self, url: StrOrURL, *, allow_redirects: bool = True, **kwargs: Any | ||||||||||||||||
| ) -> "_RequestContextManager": | ||||||||||||||||
| """Perform HTTP OPTIONS request.""" | ||||||||||||||||
| return _RequestContextManager( | ||||||||||||||||
| self._request( | ||||||||||||||||
| hdrs.METH_OPTIONS, url, allow_redirects=allow_redirects, **kwargs | ||||||||||||||||
| def options( | ||||||||||||||||
| self, url: StrOrURL, *, allow_redirects: bool = True, **kwargs: Any | ||||||||||||||||
| ) -> "_RequestContextManager": | ||||||||||||||||
| """Perform HTTP OPTIONS request.""" | ||||||||||||||||
| return _RequestContextManager( | ||||||||||||||||
| self._request( | ||||||||||||||||
| hdrs.METH_OPTIONS, url, allow_redirects=allow_redirects, **kwargs | ||||||||||||||||
| ) | ||||||||||||||||
| ) | ||||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
| def head( | ||||||||||||||||
| self, url: StrOrURL, *, allow_redirects: bool = False, **kwargs: Any | ||||||||||||||||
| ) -> "_RequestContextManager": | ||||||||||||||||
| """Perform HTTP HEAD request.""" | ||||||||||||||||
| return _RequestContextManager( | ||||||||||||||||
| self._request( | ||||||||||||||||
| hdrs.METH_HEAD, url, allow_redirects=allow_redirects, **kwargs | ||||||||||||||||
| def head( | ||||||||||||||||
| self, url: StrOrURL, *, allow_redirects: bool = False, **kwargs: Any | ||||||||||||||||
| ) -> "_RequestContextManager": | ||||||||||||||||
| """Perform HTTP HEAD request.""" | ||||||||||||||||
| return _RequestContextManager( | ||||||||||||||||
| self._request( | ||||||||||||||||
| hdrs.METH_HEAD, url, allow_redirects=allow_redirects, **kwargs | ||||||||||||||||
| ) | ||||||||||||||||
| ) | ||||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
| def post( | ||||||||||||||||
| self, url: StrOrURL, *, data: Any = None, **kwargs: Any | ||||||||||||||||
| ) -> "_RequestContextManager": | ||||||||||||||||
| """Perform HTTP POST request.""" | ||||||||||||||||
| return _RequestContextManager( | ||||||||||||||||
| self._request(hdrs.METH_POST, url, data=data, **kwargs) | ||||||||||||||||
| ) | ||||||||||||||||
| def post( | ||||||||||||||||
| self, url: StrOrURL, *, data: Any = None, **kwargs: Any | ||||||||||||||||
| ) -> "_RequestContextManager": | ||||||||||||||||
| """Perform HTTP POST request.""" | ||||||||||||||||
| return _RequestContextManager( | ||||||||||||||||
| self._request(hdrs.METH_POST, url, data=data, **kwargs) | ||||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
| def put( | ||||||||||||||||
| self, url: StrOrURL, *, data: Any = None, **kwargs: Any | ||||||||||||||||
| ) -> "_RequestContextManager": | ||||||||||||||||
| """Perform HTTP PUT request.""" | ||||||||||||||||
| return _RequestContextManager( | ||||||||||||||||
| self._request(hdrs.METH_PUT, url, data=data, **kwargs) | ||||||||||||||||
| ) | ||||||||||||||||
| def put( | ||||||||||||||||
| self, url: StrOrURL, *, data: Any = None, **kwargs: Any | ||||||||||||||||
| ) -> "_RequestContextManager": | ||||||||||||||||
| """Perform HTTP PUT request.""" | ||||||||||||||||
| return _RequestContextManager( | ||||||||||||||||
| self._request(hdrs.METH_PUT, url, data=data, **kwargs) | ||||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
| def patch( | ||||||||||||||||
| self, url: StrOrURL, *, data: Any = None, **kwargs: Any | ||||||||||||||||
Dreamsorcerer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
| ) -> "_RequestContextManager": | ||||||||||||||||
| """Perform HTTP PATCH request.""" | ||||||||||||||||
| return _RequestContextManager( | ||||||||||||||||
| self._request(hdrs.METH_PATCH, url, data=data, **kwargs) | ||||||||||||||||
| ) | ||||||||||||||||
| def patch( | ||||||||||||||||
| self, url: StrOrURL, *, data: Any = None, **kwargs: Any | ||||||||||||||||
| ) -> "_RequestContextManager": | ||||||||||||||||
| """Perform HTTP PATCH request.""" | ||||||||||||||||
| return _RequestContextManager( | ||||||||||||||||
| self._request(hdrs.METH_PATCH, url, data=data, **kwargs) | ||||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
| def delete(self, url: StrOrURL, **kwargs: Any) -> "_RequestContextManager": | ||||||||||||||||
| """Perform HTTP DELETE request.""" | ||||||||||||||||
| return _RequestContextManager(self._request(hdrs.METH_DELETE, url, **kwargs)) | ||||||||||||||||
| def delete(self, url: StrOrURL, **kwargs: Any) -> "_RequestContextManager": | ||||||||||||||||
| """Perform HTTP DELETE request.""" | ||||||||||||||||
| return _RequestContextManager( | ||||||||||||||||
| self._request(hdrs.METH_DELETE, url, **kwargs) | ||||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
| async def close(self) -> None: | ||||||||||||||||
| """Close underlying connector. | ||||||||||||||||
|
|
||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.