Repository navigation
Conversation
|
I don't think we want so much copy/paste. I think there is a better alterative coming up though: https://peps.python.org/pep-0692/ |
I think it may not be necessary to wait for version 3.12, as precise type annotations for **kwargs are now supported using TypedDict starting from MyPy version 0.981 (python/mypy#13471). This means that **kwargs: Any can now be rewritten as **kwargs: Unpack[HttpClientRequest], for example. We need to update Here is an example that works on python 3.10 import sys
from typing import (
Any,
Optional,
TypedDict,
Union
)
if sys.version_info >= (3, 11):
from typing import ( # noqa: F401
Unpack,
)
else:
from typing_extensions import ( # noqa: F401
Unpack,
)
StrOrURL = Union[str, bytes, "URL"]
class HttpClientRequest(TypedDict):
data: Optional[Union[str, bytes, dict]]
json: Optional[Union[dict, list]]
cookies: Optional[dict[str, str]]
headers: Optional[dict[str, str]]
allow_redirects: Optional[bool]
def get(url: StrOrURL, *, allow_redirects: bool = True, **kwargs: Unpack[HttpClientRequest]) -> Any:
"""
A function that sends an HTTP GET request.
:param url: The URL to send the request to.
:param allow_redirects: Whether or not to follow redirects.
:param kwargs: Additional parameters to pass to the request.
:return: The response from the server.
"""
# Example usage
param = {"data": None, "json": None, "cookies": None, "headers": None, "allow_redirects": True}
get(url="https://example.com", **param)
get(url="https://example.com", allow_redirects=True, data=None, json=None) |
That is PEP 692. It's still not stable and disabled by default (python/mypy#14697) and requires Unpack from Python 3.12. We can use typing_extensions if needed, but would be nice to start dropping typing_extensions as a dependency if possible. So, I'd probably still wait till 3.12 is released, though we can start preparing a PR beforehand if anyone wants to start looking at it. |
|
This has been done with Unpack now. |
What do these changes do?
Display ClientSession methods' parameters in the help window.
Before


After
Are there changes in behavior for the user?
Yes
Related issue number
#7185
Checklist
CONTRIBUTORS.txtCHANGESfolder<issue_id>.<type>for example (588.bugfix)issue_idchange it to the pr id after creating the pr.feature: Signifying a new feature..bugfix: Signifying a bug fix..doc: Signifying a documentation improvement..removal: Signifying a deprecation or removal of public API..misc: A ticket has been closed, but it is not of interest to users.