chore: apply ruff's pyupgrade linter rules to modernize Python code with targeted version (#2419)

This commit is contained in:
Bowen Liang 2024-02-09 15:21:33 +08:00 committed by GitHub
commit 063191889d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
246 changed files with 912 additions and 937 deletions

View file

@ -1,6 +1,6 @@
import json
from json import dumps
from typing import Any, Dict, List, Union
from typing import Any, Union
import httpx
import requests
@ -18,7 +18,7 @@ class ApiTool(Tool):
"""
Api tool
"""
def fork_tool_runtime(self, meta: Dict[str, Any]) -> 'Tool':
def fork_tool_runtime(self, meta: dict[str, Any]) -> 'Tool':
"""
fork a new tool with meta data
@ -33,7 +33,7 @@ class ApiTool(Tool):
runtime=Tool.Runtime(**meta)
)
def validate_credentials(self, credentials: Dict[str, Any], parameters: Dict[str, Any], format_only: bool = False) -> str:
def validate_credentials(self, credentials: dict[str, Any], parameters: dict[str, Any], format_only: bool = False) -> str:
"""
validate the credentials for Api tool
"""
@ -47,7 +47,7 @@ class ApiTool(Tool):
# validate response
return self.validate_and_parse_response(response)
def assembling_request(self, parameters: Dict[str, Any]) -> Dict[str, Any]:
def assembling_request(self, parameters: dict[str, Any]) -> dict[str, Any]:
headers = {}
credentials = self.runtime.credentials or {}
@ -108,7 +108,7 @@ class ApiTool(Tool):
else:
raise ValueError(f'Invalid response type {type(response)}')
def do_http_request(self, url: str, method: str, headers: Dict[str, Any], parameters: Dict[str, Any]) -> httpx.Response:
def do_http_request(self, url: str, method: str, headers: dict[str, Any], parameters: dict[str, Any]) -> httpx.Response:
"""
do http request depending on api bundle
"""
@ -225,7 +225,7 @@ class ApiTool(Tool):
return response
def _invoke(self, user_id: str, tool_parameters: Dict[str, Any]) -> ToolInvokeMessage | List[ToolInvokeMessage]:
def _invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> ToolInvokeMessage | list[ToolInvokeMessage]:
"""
invoke http request
"""