Skip to content
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

Fix FastHttpSession.request json typing #2885

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions locust/contrib/fasthttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
if TYPE_CHECKING:
import sys
from collections.abc import Callable, Generator
from typing import TypedDict
from typing import Any, TypedDict

if sys.version_info >= (3, 11):
from typing import Unpack
Expand All @@ -51,14 +51,14 @@ class PostKwargs(TypedDict, total=False):
context: dict

class PutKwargs(PostKwargs, total=False):
json: dict | None
json: Any | None

class PatchKwargs(PostKwargs, total=False):
json: dict | None
json: Any | None

class RESTKwargs(PostKwargs, total=False):
data: str | dict | None
json: dict | None
json: Any | None


# Monkey patch geventhttpclient.useragent.CompatRequest so that Cookiejar works with Python >= 3.3
Expand Down Expand Up @@ -185,7 +185,7 @@ def request(
stream: bool = False,
headers: dict | None = None,
auth: tuple[str | bytes, str | bytes] | None = None,
json: dict | None = None,
json: Any | None = None,
allow_redirects: bool = True,
context: dict = {},
**kwargs,
Expand All @@ -205,9 +205,9 @@ def request(
return a context manager to work as argument to a with statement. This will allow the
request to be marked as a fail based on the content of the response, even if the response
code is ok (2xx). The opposite also works, one can use catch_response to catch a request
and then mark it as successful even if the response code was not (i.e 500 or 404).
and then mark it as successful even if the response code was not (i.e. 500 or 404).
:param data: (optional) String/bytes to send in the body of the request.
:param json: (optional) Dictionary to send in the body of the request.
:param json: (optional) Json to send in the body of the request.
Automatically sets Content-Type and Accept headers to "application/json".
Only used if data is not set.
:param headers: (optional) Dictionary of HTTP Headers to send with the request.
Expand Down Expand Up @@ -316,7 +316,7 @@ def patch(
return self.request("PATCH", url, data=data, **kwargs)

def post(
self, url: str, data: str | dict | None = None, json: dict | None = None, **kwargs: Unpack[PostKwargs]
self, url: str, data: str | dict | None = None, json: Any | None = None, **kwargs: Unpack[PostKwargs]
) -> ResponseContextManager | FastResponse:
"""Sends a POST request"""
return self.request("POST", url, data=data, json=json, **kwargs)
Expand Down