From f356a42f40c48db4a092389587768b3d30723361 Mon Sep 17 00:00:00 2001 From: Mathijs de Bruin Date: Tue, 19 Nov 2024 16:00:36 +0000 Subject: [PATCH] All the Linters --- backend/build.py | 6 +++--- backend/chainlit/data/dynamodb.py | 4 ++-- backend/chainlit/element.py | 2 +- backend/chainlit/message.py | 6 +++--- backend/chainlit/step.py | 6 +++--- backend/pyproject.toml | 4 ++-- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/backend/build.py b/backend/build.py index acd3e5be5c..73c8ddd2b0 100644 --- a/backend/build.py +++ b/backend/build.py @@ -47,7 +47,7 @@ def copy_directory(src, dst, description): shutil.rmtree(dst) raise except Exception as e: - raise BuildError(f"Failed to copy {src} to {dst}: {str(e)}") + raise BuildError(f"Failed to copy {src} to {dst}: {e!s}") def copy_frontend(project_root): @@ -91,10 +91,10 @@ def build(): print("\nBuild interrupted by user") sys.exit(1) except BuildError as e: - print(f"\nBuild failed: {str(e)}") + print(f"\nBuild failed: {e!s}") sys.exit(1) except Exception as e: - print(f"\nUnexpected error: {str(e)}") + print(f"\nUnexpected error: {e!s}") sys.exit(1) diff --git a/backend/chainlit/data/dynamodb.py b/backend/chainlit/data/dynamodb.py index 0879ff4d3d..c04f1c9883 100644 --- a/backend/chainlit/data/dynamodb.py +++ b/backend/chainlit/data/dynamodb.py @@ -404,7 +404,7 @@ async def delete_thread(self, thread_id: str): BATCH_ITEM_SIZE = 25 # pylint: disable=invalid-name for i in range(0, len(delete_requests), BATCH_ITEM_SIZE): - chunk = delete_requests[i : i + BATCH_ITEM_SIZE] # noqa: E203 + chunk = delete_requests[i : i + BATCH_ITEM_SIZE] response = self.client.batch_write_item( RequestItems={ self.table_name: chunk, # type: ignore @@ -412,7 +412,7 @@ async def delete_thread(self, thread_id: str): ) backoff_time = 1 - while "UnprocessedItems" in response and response["UnprocessedItems"]: + while response.get("UnprocessedItems"): backoff_time *= 2 # Cap the backoff time at 32 seconds & add jitter delay = min(backoff_time, 32) + random.uniform(0, 1) diff --git a/backend/chainlit/element.py b/backend/chainlit/element.py index 4a914d7d29..3012af7b4a 100644 --- a/backend/chainlit/element.py +++ b/backend/chainlit/element.py @@ -155,7 +155,7 @@ async def _create(self) -> bool: try: asyncio.create_task(data_layer.create_element(self)) except Exception as e: - logger.error(f"Failed to create element: {str(e)}") + logger.error(f"Failed to create element: {e!s}") if not self.url and (not self.chainlit_key or self.updatable): file_dict = await context.session.persist_file( name=self.name, diff --git a/backend/chainlit/message.py b/backend/chainlit/message.py index ca3eedde79..88c071abeb 100644 --- a/backend/chainlit/message.py +++ b/backend/chainlit/message.py @@ -114,7 +114,7 @@ async def update( except Exception as e: if self.fail_on_persist_error: raise e - logger.error(f"Failed to persist message update: {str(e)}") + logger.error(f"Failed to persist message update: {e!s}") await context.emitter.update_step(step_dict) @@ -134,7 +134,7 @@ async def remove(self): except Exception as e: if self.fail_on_persist_error: raise e - logger.error(f"Failed to persist message deletion: {str(e)}") + logger.error(f"Failed to persist message deletion: {e!s}") await context.emitter.delete_step(step_dict) @@ -150,7 +150,7 @@ async def _create(self): except Exception as e: if self.fail_on_persist_error: raise e - logger.error(f"Failed to persist message creation: {str(e)}") + logger.error(f"Failed to persist message creation: {e!s}") return step_dict diff --git a/backend/chainlit/step.py b/backend/chainlit/step.py index bd61de46ec..4e7942c94a 100644 --- a/backend/chainlit/step.py +++ b/backend/chainlit/step.py @@ -318,7 +318,7 @@ async def update(self): except Exception as e: if self.fail_on_persist_error: raise e - logger.error(f"Failed to persist step update: {str(e)}") + logger.error(f"Failed to persist step update: {e!s}") tasks = [el.send(for_id=self.id) for el in self.elements] await asyncio.gather(*tasks) @@ -345,7 +345,7 @@ async def remove(self): except Exception as e: if self.fail_on_persist_error: raise e - logger.error(f"Failed to persist step deletion: {str(e)}") + logger.error(f"Failed to persist step deletion: {e!s}") await context.emitter.delete_step(step_dict) @@ -372,7 +372,7 @@ async def send(self): except Exception as e: if self.fail_on_persist_error: raise e - logger.error(f"Failed to persist step creation: {str(e)}") + logger.error(f"Failed to persist step creation: {e!s}") tasks = [el.send(for_id=self.id) for el in self.elements] await asyncio.gather(*tasks) diff --git a/backend/pyproject.toml b/backend/pyproject.toml index 01f494deeb..65452404a1 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", "UP", "T10", "ISC", "ICN", "LOG", "G", "PIE", "PT", "Q", "RSE"] -ignore = ["E712", "E501", "UP006", "UP035","PIE790", "PT004"] +select = ["E", "F", "I", "LOG", "UP", "T10", "ISC", "ICN", "LOG", "G", "PIE", "PT", "Q", "RSE", "FURB", "RUF"] +ignore = ["E712", "E501", "UP006", "UP035","PIE790", "PT004", "RUF005", "RUF006", "RUF012"] [tool.ruff.lint.isort] combine-as-imports = true