From 99fec40117cbd99bce907c22756bb73bb7220c5d Mon Sep 17 00:00:00 2001 From: Asuka Minato Date: Tue, 26 Aug 2025 00:16:59 +0900 Subject: [PATCH] example of remove some reflections (#24488) Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- api/core/tools/custom_tool/tool.py | 51 ++++++++++++++---------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/api/core/tools/custom_tool/tool.py b/api/core/tools/custom_tool/tool.py index 3c0bfa524..97342640f 100644 --- a/api/core/tools/custom_tool/tool.py +++ b/api/core/tools/custom_tool/tool.py @@ -275,35 +275,30 @@ class ApiTool(Tool): if files: headers.pop("Content-Type", None) - if method in { - "get", - "head", - "post", - "put", - "delete", - "patch", - "options", - "GET", - "POST", - "PUT", - "PATCH", - "DELETE", - "HEAD", - "OPTIONS", - }: - response: httpx.Response = getattr(ssrf_proxy, method.lower())( - url, - params=params, - headers=headers, - cookies=cookies, - data=body, - files=files, - timeout=API_TOOL_DEFAULT_TIMEOUT, - follow_redirects=True, - ) - return response - else: + _METHOD_MAP = { + "get": ssrf_proxy.get, + "head": ssrf_proxy.head, + "post": ssrf_proxy.post, + "put": ssrf_proxy.put, + "delete": ssrf_proxy.delete, + "patch": ssrf_proxy.patch, + } + method_lc = method.lower() + if method_lc not in _METHOD_MAP: raise ValueError(f"Invalid http method {method}") + response: httpx.Response = _METHOD_MAP[ + method_lc + ]( # https://discuss.python.org/t/type-inference-for-function-return-types/42926 + url, + params=params, + headers=headers, + cookies=cookies, + data=body, + files=files, + timeout=API_TOOL_DEFAULT_TIMEOUT, + follow_redirects=True, + ) + return response def _convert_body_property_any_of( self, property: dict[str, Any], value: Any, any_of: list[dict[str, Any]], max_recursive=10