From c4f7d861709fb59061f5730eff2743dedbb543a2 Mon Sep 17 00:00:00 2001 From: tdadela Date: Fri, 6 Sep 2024 00:19:05 +0200 Subject: [PATCH] fix(typing): rm redundant None in Any | None annotations --- locust/clients.py | 36 ++++++++++++++++++------------------ locust/contrib/fasthttp.py | 10 +++++----- locust/runners.py | 4 ++-- locust/stats.py | 2 +- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/locust/clients.py b/locust/clients.py index d8bc755811..40fa2af776 100644 --- a/locust/clients.py +++ b/locust/clients.py @@ -31,11 +31,11 @@ # Mypy underneath uses information from the https://github.com/python/typeshed repo. class RequestKwargs(TypedDict, total=False): - params: Any | None # simplified signature + params: Any # simplified signature headers: Mapping[str, str | bytes | None] | None cookies: RequestsCookieJar | MutableMapping[str, str] | None - files: Any | None # simplified signature - auth: Any | None # simplified signature + files: Any # simplified signature + auth: Any # simplified signature timeout: float | tuple[float, float] | tuple[float, None] | None allow_redirects: bool proxies: MutableMapping[str, str] | None @@ -139,8 +139,8 @@ def request( # type: ignore[override] catch_response: bool = False, context: dict = {}, *, - data: Any | None = None, - json: Any | None = None, + data: Any = None, + json: Any = None, **kwargs: Unpack[RequestKwargs], ): """ @@ -245,7 +245,7 @@ def _send_request_safe_mode(self, method, url, **kwargs) -> Response | LocustRes return r def get( - self, url: str | bytes, *, data: Any | None = None, json: Any | None = None, **kwargs: Unpack[RESTKwargs] + self, url: str | bytes, *, data: Any = None, json: Any = None, **kwargs: Unpack[RESTKwargs] ) -> ResponseContextManager | Response | LocustResponse: """Sends a GET request""" kwargs.setdefault("allow_redirects", True) @@ -255,8 +255,8 @@ def options( self, url: str | bytes, *, - data: Any | None = None, - json: Any | None = None, + data: Any = None, + json: Any = None, **kwargs: Unpack[RESTKwargs], ) -> ResponseContextManager | Response | LocustResponse: """Sends a OPTIONS request""" @@ -267,8 +267,8 @@ def head( self, url: str | bytes, *, - data: Any | None = None, - json: Any | None = None, + data: Any = None, + json: Any = None, **kwargs: Unpack[RESTKwargs], ) -> ResponseContextManager | Response | LocustResponse: """Sends a HEAD request""" @@ -278,8 +278,8 @@ def head( def post( self, url: str | bytes, - data: Any | None = None, - json: Any | None = None, + data: Any = None, + json: Any = None, **kwargs: Unpack[RESTKwargs], ) -> ResponseContextManager | Response | LocustResponse: """Sends a POST request""" @@ -288,9 +288,9 @@ def post( def put( self, url: str | bytes, - data: Any | None = None, + data: Any = None, *, - json: Any | None = None, + json: Any = None, **kwargs: Unpack[RESTKwargs], ) -> ResponseContextManager | Response | LocustResponse: """Sends a PUT request""" @@ -299,9 +299,9 @@ def put( def patch( self, url: str | bytes, - data: Any | None = None, + data: Any = None, *, - json: Any | None = None, + json: Any = None, **kwargs: Unpack[RESTKwargs], ) -> ResponseContextManager | Response | LocustResponse: """Sends a PATCH request""" @@ -311,8 +311,8 @@ def delete( self, url: str | bytes, *, - data: Any | None = None, - json: Any | None = None, + data: Any = None, + json: Any = None, **kwargs: Unpack[RESTKwargs], ) -> ResponseContextManager | Response | LocustResponse: """Sends a DELETE request""" diff --git a/locust/contrib/fasthttp.py b/locust/contrib/fasthttp.py index f52eac936a..c23457f083 100644 --- a/locust/contrib/fasthttp.py +++ b/locust/contrib/fasthttp.py @@ -51,14 +51,14 @@ class PostKwargs(TypedDict, total=False): context: dict class PutKwargs(PostKwargs, total=False): - json: Any | None + json: Any class PatchKwargs(PostKwargs, total=False): - json: Any | None + json: Any class RESTKwargs(PostKwargs, total=False): data: str | dict | None - json: Any | None + json: Any # Monkey patch geventhttpclient.useragent.CompatRequest so that Cookiejar works with Python >= 3.3 @@ -185,7 +185,7 @@ def request( stream: bool = False, headers: dict | None = None, auth: tuple[str | bytes, str | bytes] | None = None, - json: Any | None = None, + json: Any = None, allow_redirects: bool = True, context: dict = {}, **kwargs, @@ -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: Any | None = None, **kwargs: Unpack[PostKwargs] + self, url: str, data: str | dict | None = None, json: Any = None, **kwargs: Unpack[PostKwargs] ) -> ResponseContextManager | FastResponse: """Sends a POST request""" return self.request("POST", url, data=data, json=json, **kwargs) diff --git a/locust/runners.py b/locust/runners.py index ae30bda97c..6fe641d1b7 100644 --- a/locust/runners.py +++ b/locust/runners.py @@ -305,7 +305,7 @@ def start( ) -> None: ... @abstractmethod - def send_message(self, msg_type: str, data: Any | None = None, client_id: str | None = None) -> None: ... + def send_message(self, msg_type: str, data: Any = None, client_id: str | None = None) -> None: ... def start_shape(self) -> None: """ @@ -550,7 +550,7 @@ def stop(self) -> None: return super().stop() - def send_message(self, msg_type: str, data: Any | None = None, client_id: str | None = None) -> None: + def send_message(self, msg_type: str, data: Any = None, client_id: str | None = None) -> None: """ Emulates internodal messaging by calling registered listeners diff --git a/locust/stats.py b/locust/stats.py index 52c76767b8..0a38b77c77 100644 --- a/locust/stats.py +++ b/locust/stats.py @@ -739,7 +739,7 @@ def to_name(self) -> str: return f"{self.method} {self.name}: {unwrapped_error}" def serialize(self) -> StatsErrorDict: - def _getattr(obj: StatsError, key: str, default: Any | None) -> Any | None: + def _getattr(obj: StatsError, key: str, default: Any) -> Any: value = getattr(obj, key, default) if key in ["error"]: