From 918130fc849d337d7ddb27f7e783905a60e9ae0e Mon Sep 17 00:00:00 2001 From: Mathijs de Bruin Date: Tue, 19 Nov 2024 15:32:42 +0000 Subject: [PATCH] Upgrade Python syntax. --- backend/chainlit/config.py | 6 +++--- backend/chainlit/data/sql_alchemy.py | 2 +- backend/chainlit/emitter.py | 2 +- backend/chainlit/langchain/callbacks.py | 2 +- backend/chainlit/secret.py | 2 +- backend/chainlit/server.py | 2 +- backend/chainlit/session.py | 4 ++-- backend/pyproject.toml | 4 ++-- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/backend/chainlit/config.py b/backend/chainlit/config.py index 71fa8fca1f..f146c56862 100644 --- a/backend/chainlit/config.py +++ b/backend/chainlit/config.py @@ -399,7 +399,7 @@ def init_config(log=False): dst = os.path.join(config_translation_dir, file) if not os.path.exists(dst): src = os.path.join(TRANSLATIONS_DIR, file) - with open(src, "r", encoding="utf-8") as f: + with open(src, encoding="utf-8") as f: translation = json.load(f) with open(dst, "w", encoding="utf-8") as f: json.dump(translation, f, indent=4) @@ -514,7 +514,7 @@ def load_config(): def lint_translations(): # Load the ground truth (en-US.json file from chainlit source code) src = os.path.join(TRANSLATIONS_DIR, "en-US.json") - with open(src, "r", encoding="utf-8") as f: + with open(src, encoding="utf-8") as f: truth = json.load(f) # Find the local app translations @@ -522,7 +522,7 @@ def lint_translations(): if file.endswith(".json"): # Load the translation file to_lint = os.path.join(config_translation_dir, file) - with open(to_lint, "r", encoding="utf-8") as f: + with open(to_lint, encoding="utf-8") as f: translation = json.load(f) # Lint the translation file diff --git a/backend/chainlit/data/sql_alchemy.py b/backend/chainlit/data/sql_alchemy.py index 9ed62a3bb2..5a694b081f 100644 --- a/backend/chainlit/data/sql_alchemy.py +++ b/backend/chainlit/data/sql_alchemy.py @@ -168,7 +168,7 @@ async def _get_user_id_by_thread(self, thread_id: str) -> Optional[str]: async def create_user(self, user: User) -> Optional[PersistedUser]: if self.show_logger: logger.info(f"SQLAlchemy: create_user, user_identifier={user.identifier}") - existing_user: Optional["PersistedUser"] = await self.get_user(user.identifier) + existing_user: Optional[PersistedUser] = await self.get_user(user.identifier) user_dict: Dict[str, Any] = { "identifier": str(user.identifier), "metadata": json.dumps(user.metadata) or {}, diff --git a/backend/chainlit/emitter.py b/backend/chainlit/emitter.py index 2ef1bf2d9d..b3b1217fbe 100644 --- a/backend/chainlit/emitter.py +++ b/backend/chainlit/emitter.py @@ -285,7 +285,7 @@ async def send_ask_user( await self.task_end() final_res: Optional[ - Union["StepDict", "AskActionResponse", List["FileDict"]] + Union[StepDict, AskActionResponse, List[FileDict]] ] = None if user_res: diff --git a/backend/chainlit/langchain/callbacks.py b/backend/chainlit/langchain/callbacks.py index 2f2aadc172..7f5ee92c19 100644 --- a/backend/chainlit/langchain/callbacks.py +++ b/backend/chainlit/langchain/callbacks.py @@ -460,7 +460,7 @@ def _start_trace(self, run: Run) -> None: if ignore: return - step_type: "TrueStepType" = "undefined" + step_type: TrueStepType = "undefined" if run.run_type == "agent": step_type = "run" elif run.run_type == "chain": diff --git a/backend/chainlit/secret.py b/backend/chainlit/secret.py index 968193bf16..cc85257abe 100644 --- a/backend/chainlit/secret.py +++ b/backend/chainlit/secret.py @@ -6,4 +6,4 @@ def random_secret(length: int = 64): - return "".join((secrets.choice(chars) for i in range(length))) + return "".join(secrets.choice(chars) for i in range(length)) diff --git a/backend/chainlit/server.py b/backend/chainlit/server.py index bee77bb2f6..259cf57e14 100644 --- a/backend/chainlit/server.py +++ b/backend/chainlit/server.py @@ -317,7 +317,7 @@ def get_html_template(): index_html_file_path = os.path.join(build_dir, "index.html") - with open(index_html_file_path, "r", encoding="utf-8") as f: + with open(index_html_file_path, encoding="utf-8") as f: content = f.read() content = content.replace(PLACEHOLDER, tags) if js: diff --git a/backend/chainlit/session.py b/backend/chainlit/session.py index 95a34cf8ad..404713ec92 100644 --- a/backend/chainlit/session.py +++ b/backend/chainlit/session.py @@ -18,9 +18,9 @@ class JSONEncoderIgnoreNonSerializable(json.JSONEncoder): - def default(self, obj): + def default(self, o): try: - return super(JSONEncoderIgnoreNonSerializable, self).default(obj) + return super().default(o) except TypeError: return None diff --git a/backend/pyproject.toml b/backend/pyproject.toml index ff152e7d87..3aebd47de8 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -145,8 +145,8 @@ target-version = "py39" line-length = 120 [tool.ruff.lint] -select = ["E", "F", "I", "LOG"] -ignore = ["E712", "E501"] +select = ["E", "F", "I", "LOG", "UP"] +ignore = ["E712", "E501", "UP006", "UP035"] [tool.ruff.lint.isort] combine-as-imports = true