diff --git a/backend/chainlit/config.py b/backend/chainlit/config.py index d59da1bca1..5a0d2c4178 100644 --- a/backend/chainlit/config.py +++ b/backend/chainlit/config.py @@ -400,7 +400,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) @@ -515,7 +515,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 @@ -523,7 +523,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 5cc6a905b6..1f1950ad63 100644 --- a/backend/chainlit/emitter.py +++ b/backend/chainlit/emitter.py @@ -289,7 +289,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 7449663dd4..526002cd36 100644 --- a/backend/chainlit/langchain/callbacks.py +++ b/backend/chainlit/langchain/callbacks.py @@ -468,7 +468,7 @@ async 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