From db8a2e4e48391e44121cae332272fa63bfafd3c3 Mon Sep 17 00:00:00 2001 From: Collin Dutter Date: Fri, 5 Jul 2024 09:14:22 -0700 Subject: [PATCH] Update ruff linter rules according to documentation --- griptape/artifacts/base_artifact.py | 5 +- griptape/chunkers/base_chunker.py | 5 +- .../amazon_s3_file_manager_driver.py | 2 +- .../file_manager/base_file_manager_driver.py | 7 +- .../amazon_bedrock_image_generation_driver.py | 2 +- .../amazon_bedrock_image_query_driver.py | 2 +- .../drivers/prompt/anthropic_prompt_driver.py | 5 +- griptape/drivers/prompt/base_prompt_driver.py | 5 +- .../drivers/prompt/cohere_prompt_driver.py | 5 +- .../vector/base_vector_store_driver.py | 5 +- .../mongodb_atlas_vector_store_driver.py | 5 +- .../markdownify_web_scraper_driver.py | 67 +++++++++---------- .../duck_duck_go_web_search_driver.py | 2 +- griptape/loaders/base_text_loader.py | 5 +- griptape/loaders/sql_loader.py | 5 +- griptape/mixins/rule_mixin.py | 5 +- griptape/mixins/serializable_mixin.py | 2 +- griptape/schemas/polymorphic_schema.py | 8 +-- griptape/structures/structure.py | 12 +--- griptape/structures/workflow.py | 4 +- griptape/tasks/actions_subtask.py | 14 ++-- griptape/tasks/base_task.py | 2 +- griptape/tasks/prompt_task.py | 2 +- griptape/tokenizers/base_tokenizer.py | 3 +- griptape/utils/chat.py | 9 ++- griptape/utils/dict_utils.py | 2 +- griptape/utils/import_utils.py | 4 +- griptape/utils/load_artifact_from_memory.py | 4 +- pyproject.toml | 17 ++++- tests/utils/code_blocks.py | 3 +- 30 files changed, 98 insertions(+), 120 deletions(-) diff --git a/griptape/artifacts/base_artifact.py b/griptape/artifacts/base_artifact.py index a7a1811eab..ced8e0e1c2 100644 --- a/griptape/artifacts/base_artifact.py +++ b/griptape/artifacts/base_artifact.py @@ -24,10 +24,7 @@ def value_to_bytes(cls, value: Any) -> bytes: @classmethod def value_to_dict(cls, value: Any) -> dict: - if isinstance(value, dict): - dict_value = value - else: - dict_value = json.loads(value) + dict_value = value if isinstance(value, dict) else json.loads(value) return {k: v for k, v in dict_value.items()} diff --git a/griptape/chunkers/base_chunker.py b/griptape/chunkers/base_chunker.py index 793bf24ade..26199a16c7 100644 --- a/griptape/chunkers/base_chunker.py +++ b/griptape/chunkers/base_chunker.py @@ -58,10 +58,7 @@ def _chunk_recursively(self, chunk: str, current_separator: Optional[ChunkSepara # Iterate through the subchunks and calculate token counts. for index, subchunk in enumerate(subchunks): if index < len(subchunks): - if separator.is_prefix: - subchunk = separator.value + subchunk - else: - subchunk = subchunk + separator.value + subchunk = separator.value + subchunk if separator.is_prefix else subchunk + separator.value tokens_count += self.tokenizer.count_tokens(subchunk) diff --git a/griptape/drivers/file_manager/amazon_s3_file_manager_driver.py b/griptape/drivers/file_manager/amazon_s3_file_manager_driver.py index bdb4d787cc..e2d794f31c 100644 --- a/griptape/drivers/file_manager/amazon_s3_file_manager_driver.py +++ b/griptape/drivers/file_manager/amazon_s3_file_manager_driver.py @@ -55,7 +55,7 @@ def try_load_file(self, path: str) -> bytes: return response["Body"].read() except botocore.exceptions.ClientError as e: if e.response["Error"]["Code"] in {"NoSuchKey", "404"}: - raise FileNotFoundError + raise FileNotFoundError from e else: raise e diff --git a/griptape/drivers/file_manager/base_file_manager_driver.py b/griptape/drivers/file_manager/base_file_manager_driver.py index 562d8be4c4..9b8fe83255 100644 --- a/griptape/drivers/file_manager/base_file_manager_driver.py +++ b/griptape/drivers/file_manager/base_file_manager_driver.py @@ -82,11 +82,8 @@ def save_file(self, path: str, value: bytes | str) -> InfoArtifact | ErrorArtifa encoding = None if loader is None else loader.encoding if isinstance(value, str): - if encoding is None: - value = value.encode() - else: - value = value.encode(encoding=encoding) - elif isinstance(value, bytearray) or isinstance(value, memoryview): + value = value.encode() if encoding is None else value.encode(encoding=encoding) + elif isinstance(value, (bytearray, memoryview)): raise ValueError(f"Unsupported type: {type(value)}") self.try_save_file(path, value) diff --git a/griptape/drivers/image_generation/amazon_bedrock_image_generation_driver.py b/griptape/drivers/image_generation/amazon_bedrock_image_generation_driver.py index 2edb9f8629..b5a4b7e3b5 100644 --- a/griptape/drivers/image_generation/amazon_bedrock_image_generation_driver.py +++ b/griptape/drivers/image_generation/amazon_bedrock_image_generation_driver.py @@ -122,6 +122,6 @@ def _make_request(self, request: dict) -> bytes: try: image_bytes = self.image_generation_model_driver.get_generated_image(response_body) except Exception as e: - raise ValueError(f"Inpainting generation failed: {e}") + raise ValueError(f"Inpainting generation failed: {e}") from e return image_bytes diff --git a/griptape/drivers/image_query/amazon_bedrock_image_query_driver.py b/griptape/drivers/image_query/amazon_bedrock_image_query_driver.py index eabe9d27e2..e91cbbedc6 100644 --- a/griptape/drivers/image_query/amazon_bedrock_image_query_driver.py +++ b/griptape/drivers/image_query/amazon_bedrock_image_query_driver.py @@ -32,4 +32,4 @@ def try_query(self, query: str, images: list[ImageArtifact]) -> TextArtifact: try: return self.image_query_model_driver.process_output(response_body) except Exception as e: - raise ValueError(f"Output is unable to be processed as returned {e}") + raise ValueError(f"Output is unable to be processed as returned {e}") from e diff --git a/griptape/drivers/prompt/anthropic_prompt_driver.py b/griptape/drivers/prompt/anthropic_prompt_driver.py index 1dd7bb7f95..2c338c84c4 100644 --- a/griptape/drivers/prompt/anthropic_prompt_driver.py +++ b/griptape/drivers/prompt/anthropic_prompt_driver.py @@ -77,10 +77,7 @@ def _base_params(self, prompt_stack: PromptStack) -> dict: ) system_messages = prompt_stack.system_messages - if system_messages: - system_message = system_messages[0].to_text() - else: - system_message = None + system_message = system_messages[0].to_text() if system_messages else None return { "model": self.model, diff --git a/griptape/drivers/prompt/base_prompt_driver.py b/griptape/drivers/prompt/base_prompt_driver.py index f42e57081d..b499179ed3 100644 --- a/griptape/drivers/prompt/base_prompt_driver.py +++ b/griptape/drivers/prompt/base_prompt_driver.py @@ -65,10 +65,7 @@ def run(self, prompt_stack: PromptStack) -> Message: with attempt: self.before_run(prompt_stack) - if self.stream: - result = self.__process_stream(prompt_stack) - else: - result = self.__process_run(prompt_stack) + result = self.__process_stream(prompt_stack) if self.stream else self.__process_run(prompt_stack) self.after_run(result) diff --git a/griptape/drivers/prompt/cohere_prompt_driver.py b/griptape/drivers/prompt/cohere_prompt_driver.py index 331c2c039f..b00abd855e 100644 --- a/griptape/drivers/prompt/cohere_prompt_driver.py +++ b/griptape/drivers/prompt/cohere_prompt_driver.py @@ -79,10 +79,7 @@ def _base_params(self, prompt_stack: PromptStack) -> dict: ) system_messages = prompt_stack.system_messages - if system_messages: - preamble = system_messages[0].to_text() - else: - preamble = None + preamble = system_messages[0].to_text() if system_messages else None return { "message": user_message, diff --git a/griptape/drivers/vector/base_vector_store_driver.py b/griptape/drivers/vector/base_vector_store_driver.py index 5a4130a88b..72ed2c3225 100644 --- a/griptape/drivers/vector/base_vector_store_driver.py +++ b/griptape/drivers/vector/base_vector_store_driver.py @@ -64,10 +64,7 @@ def upsert_text_artifact( else: meta["artifact"] = artifact.to_json() - if artifact.embedding: - vector = artifact.embedding - else: - vector = artifact.generate_embedding(self.embedding_driver) + vector = artifact.embedding if artifact.embedding else artifact.generate_embedding(self.embedding_driver) if isinstance(vector, list): return self.upsert_vector(vector, vector_id=vector_id, namespace=namespace, meta=meta, **kwargs) diff --git a/griptape/drivers/vector/mongodb_atlas_vector_store_driver.py b/griptape/drivers/vector/mongodb_atlas_vector_store_driver.py index 73bcc02c72..e605247143 100644 --- a/griptape/drivers/vector/mongodb_atlas_vector_store_driver.py +++ b/griptape/drivers/vector/mongodb_atlas_vector_store_driver.py @@ -90,10 +90,7 @@ def load_entries(self, namespace: Optional[str] = None) -> list[BaseVectorStoreD Entries can optionally be filtered by namespace. """ collection = self.get_collection() - if namespace is None: - cursor = collection.find() - else: - cursor = collection.find({"namespace": namespace}) + cursor = collection.find() if namespace is None else collection.find({"namespace": namespace}) return [ BaseVectorStoreDriver.Entry( diff --git a/griptape/drivers/web_scraper/markdownify_web_scraper_driver.py b/griptape/drivers/web_scraper/markdownify_web_scraper_driver.py index eb33aeb19f..28f225ba8e 100644 --- a/griptape/drivers/web_scraper/markdownify_web_scraper_driver.py +++ b/griptape/drivers/web_scraper/markdownify_web_scraper_driver.py @@ -48,51 +48,50 @@ def convert_a(self, el, text, convert_as_inline): return super().convert_a(el, text, convert_as_inline) return text - with sync_playwright() as p: - with p.chromium.launch(headless=True) as browser: - page = browser.new_page() + with sync_playwright() as p, p.chromium.launch(headless=True) as browser: + page = browser.new_page() - def skip_loading_images(route): - if route.request.resource_type == "image": - return route.abort() - route.continue_() + def skip_loading_images(route): + if route.request.resource_type == "image": + return route.abort() + route.continue_() - page.route("**/*", skip_loading_images) + page.route("**/*", skip_loading_images) - page.goto(url) + page.goto(url) - # Some websites require a delay before the content is fully loaded - # even after the browser has emitted "load" event. - if self.timeout: - page.wait_for_timeout(self.timeout) + # Some websites require a delay before the content is fully loaded + # even after the browser has emitted "load" event. + if self.timeout: + page.wait_for_timeout(self.timeout) - content = page.content() + content = page.content() - if not content: - raise Exception("can't access URL") + if not content: + raise Exception("can't access URL") - soup = BeautifulSoup(content, "html.parser") + soup = BeautifulSoup(content, "html.parser") - # Remove unwanted elements - exclude_selector = ",".join( - self.exclude_tags + [f".{c}" for c in self.exclude_classes] + [f"#{i}" for i in self.exclude_ids] - ) - if exclude_selector: - for s in soup.select(exclude_selector): - s.extract() + # Remove unwanted elements + exclude_selector = ",".join( + self.exclude_tags + [f".{c}" for c in self.exclude_classes] + [f"#{i}" for i in self.exclude_ids] + ) + if exclude_selector: + for s in soup.select(exclude_selector): + s.extract() - text = OptionalLinksMarkdownConverter().convert_soup(soup) + text = OptionalLinksMarkdownConverter().convert_soup(soup) - # Remove leading and trailing whitespace from the entire text - text = text.strip() + # Remove leading and trailing whitespace from the entire text + text = text.strip() - # Remove trailing whitespace from each line - text = re.sub(r"[ \t]+$", "", text, flags=re.MULTILINE) + # Remove trailing whitespace from each line + text = re.sub(r"[ \t]+$", "", text, flags=re.MULTILINE) - # Indent using 2 spaces instead of tabs - text = re.sub(r"(\n?\s*?)\t", r"\1 ", text) + # Indent using 2 spaces instead of tabs + text = re.sub(r"(\n?\s*?)\t", r"\1 ", text) - # Remove triple+ newlines (keep double newlines for paragraphs) - text = re.sub(r"\n\n+", "\n\n", text) + # Remove triple+ newlines (keep double newlines for paragraphs) + text = re.sub(r"\n\n+", "\n\n", text) - return TextArtifact(text) + return TextArtifact(text) diff --git a/griptape/drivers/web_search/duck_duck_go_web_search_driver.py b/griptape/drivers/web_search/duck_duck_go_web_search_driver.py index 9b90bf5ff6..ade6ed85cc 100644 --- a/griptape/drivers/web_search/duck_duck_go_web_search_driver.py +++ b/griptape/drivers/web_search/duck_duck_go_web_search_driver.py @@ -26,4 +26,4 @@ def search(self, query: str, **kwargs) -> ListArtifact: ] ) except Exception as e: - raise Exception(f"Error searching '{query}' with DuckDuckGo: {e}") + raise Exception(f"Error searching '{query}' with DuckDuckGo: {e}") from e diff --git a/griptape/loaders/base_text_loader.py b/griptape/loaders/base_text_loader.py index f09b57902c..c2840d62f8 100644 --- a/griptape/loaders/base_text_loader.py +++ b/griptape/loaders/base_text_loader.py @@ -41,10 +41,7 @@ def load_collection(self, sources: list[Any], *args, **kwargs) -> dict[str, Erro def _text_to_artifacts(self, text: str) -> list[TextArtifact]: artifacts = [] - if self.chunker: - chunks = self.chunker.chunk(text) - else: - chunks = [TextArtifact(text)] + chunks = self.chunker.chunk(text) if self.chunker else [TextArtifact(text)] if self.embedding_driver: for chunk in chunks: diff --git a/griptape/loaders/sql_loader.py b/griptape/loaders/sql_loader.py index c20fb022d1..e6979e3243 100644 --- a/griptape/loaders/sql_loader.py +++ b/griptape/loaders/sql_loader.py @@ -16,10 +16,7 @@ def load(self, source: str, *args, **kwargs) -> list[CsvRowArtifact]: rows = self.sql_driver.execute_query(source) artifacts = [] - if rows: - chunks = [CsvRowArtifact(row.cells) for row in rows] - else: - chunks = [] + chunks = [CsvRowArtifact(row.cells) for row in rows] if rows else [] if self.embedding_driver: for chunk in chunks: diff --git a/griptape/mixins/rule_mixin.py b/griptape/mixins/rule_mixin.py index a89309a151..0cc696242d 100644 --- a/griptape/mixins/rule_mixin.py +++ b/griptape/mixins/rule_mixin.py @@ -49,10 +49,7 @@ def all_rulesets(self) -> list[Ruleset]: if self.rulesets: task_rulesets = self.rulesets elif self.rules: - if structure_rulesets: - task_ruleset_name = self.ADDITIONAL_RULESET_NAME - else: - task_ruleset_name = self.DEFAULT_RULESET_NAME + task_ruleset_name = self.ADDITIONAL_RULESET_NAME if structure_rulesets else self.DEFAULT_RULESET_NAME task_rulesets = [Ruleset(name=task_ruleset_name, rules=self.rules)] diff --git a/griptape/mixins/serializable_mixin.py b/griptape/mixins/serializable_mixin.py index c7a0bf035e..667ae752db 100644 --- a/griptape/mixins/serializable_mixin.py +++ b/griptape/mixins/serializable_mixin.py @@ -42,7 +42,7 @@ def get_schema(cls: type[T], subclass_name: Optional[str] = None) -> Schema: @classmethod def from_dict(cls: type[T], data: dict) -> T: - return cast(T, cls.get_schema(subclass_name=data["type"] if "type" in data else None).load(data)) + return cast(T, cls.get_schema(subclass_name=data.get("type")).load(data)) @classmethod def from_json(cls: type[T], data: str) -> T: diff --git a/griptape/schemas/polymorphic_schema.py b/griptape/schemas/polymorphic_schema.py index 534ba8ffc6..452e3001f2 100644 --- a/griptape/schemas/polymorphic_schema.py +++ b/griptape/schemas/polymorphic_schema.py @@ -58,12 +58,12 @@ def _dump(self, obj, *, update_fields=True, **kwargs): obj_type = self.get_obj_type(obj) if not obj_type: - return (None, {"_schema": "Unknown object class: %s" % obj.__class__.__name__}) + return (None, {"_schema": f"Unknown object class: {obj.__class__.__name__}"}) type_schema = BaseSchema.from_attrs_cls(obj.__class__) if not type_schema: - return None, {"_schema": "Unsupported object type: %s" % obj_type} + return None, {"_schema": f"Unsupported object type: {obj_type}"} schema = type_schema if isinstance(type_schema, Schema) else type_schema() @@ -110,7 +110,7 @@ def load(self, data, *, many=None, partial=None, unknown=None, **kwargs): def _load(self, data, *, partial=None, unknown=None, **kwargs): if not isinstance(data, dict): - raise ValidationError({"_schema": "Invalid data type: %s" % data}) + raise ValidationError({"_schema": f"Invalid data type: {data}"}) data = dict(data) unknown = unknown or self.unknown @@ -121,7 +121,7 @@ def _load(self, data, *, partial=None, unknown=None, **kwargs): type_schema = self.inner_class.get_schema(data_type) if not type_schema: - raise ValidationError({self.type_field: ["Unsupported value: %s" % data_type]}) + raise ValidationError({self.type_field: [f"Unsupported value: {data_type}"]}) schema = type_schema if isinstance(type_schema, Schema) else type_schema() diff --git a/griptape/structures/structure.py b/griptape/structures/structure.py index 18e7d12845..c7b7795904 100644 --- a/griptape/structures/structure.py +++ b/griptape/structures/structure.py @@ -147,15 +147,9 @@ def default_config(self) -> BaseStructureConfig: if self.prompt_driver is not None or self.embedding_driver is not None or self.stream is not None: config = StructureConfig() - if self.prompt_driver is None: - prompt_driver = OpenAiChatPromptDriver(model="gpt-4o") - else: - prompt_driver = self.prompt_driver - - if self.embedding_driver is None: - embedding_driver = OpenAiEmbeddingDriver() - else: - embedding_driver = self.embedding_driver + prompt_driver = OpenAiChatPromptDriver(model="gpt-4o") if self.prompt_driver is None else self.prompt_driver + + embedding_driver = OpenAiEmbeddingDriver() if self.embedding_driver is None else self.embedding_driver if self.stream is not None: prompt_driver.stream = self.stream diff --git a/griptape/structures/workflow.py b/griptape/structures/workflow.py index 3689f73307..f7bc2e8931 100644 --- a/griptape/structures/workflow.py +++ b/griptape/structures/workflow.py @@ -89,8 +89,8 @@ def insert_task( try: parent_index = self.tasks.index(parent_task) - except ValueError: - raise ValueError(f"Parent task {parent_task.id} not found in workflow.") + except ValueError as exc: + raise ValueError(f"Parent task {parent_task.id} not found in workflow.") from exc else: if parent_index > last_parent_index: last_parent_index = parent_index diff --git a/griptape/tasks/actions_subtask.py b/griptape/tasks/actions_subtask.py index fa2aff8226..c835f2b84b 100644 --- a/griptape/tasks/actions_subtask.py +++ b/griptape/tasks/actions_subtask.py @@ -112,11 +112,10 @@ def run(self) -> BaseArtifact: self.structure.logger.error(f"Subtask {self.id}\n{e}", exc_info=True) self.output = ErrorArtifact(str(e), exception=e) - finally: - if self.output is not None: - return self.output - else: - return ErrorArtifact("no tool output") + if self.output is not None: + return self.output + else: + return ErrorArtifact("no tool output") def execute_actions(self, actions: list[Action]) -> list[tuple[str, BaseArtifact]]: with self.futures_executor_fn() as executor: @@ -234,9 +233,8 @@ def __parse_actions(self, actions_matches: list[str]) -> None: tag=action_tag, name=action_name, path=action_path, input=action_input, tool=tool ) - if new_action.tool: - if new_action.input: - self.__validate_action(new_action) + if new_action.tool and new_action.input: + self.__validate_action(new_action) # Don't forget to add it to the subtask actions list! self.actions.append(new_action) diff --git a/griptape/tasks/base_task.py b/griptape/tasks/base_task.py index be5ff94d8c..9aa891e18a 100644 --- a/griptape/tasks/base_task.py +++ b/griptape/tasks/base_task.py @@ -144,7 +144,7 @@ def execute(self) -> Optional[BaseArtifact]: finally: self.state = BaseTask.State.FINISHED - return self.output + return self.output def can_execute(self) -> bool: return self.state == BaseTask.State.PENDING and all(parent.is_finished() for parent in self.parents) diff --git a/griptape/tasks/prompt_task.py b/griptape/tasks/prompt_task.py index dba542d60f..955855e3d9 100644 --- a/griptape/tasks/prompt_task.py +++ b/griptape/tasks/prompt_task.py @@ -102,7 +102,7 @@ def _process_task_input( return self._process_task_input(task_input(self)) elif isinstance(task_input, BaseArtifact): return task_input - elif isinstance(task_input, list) or isinstance(task_input, tuple): + elif isinstance(task_input, (list, tuple)): return ListArtifact([self._process_task_input(elem) for elem in task_input]) else: return self._process_task_input(TextArtifact(task_input)) diff --git a/griptape/tokenizers/base_tokenizer.py b/griptape/tokenizers/base_tokenizer.py index 474ccbaa57..212e400589 100644 --- a/griptape/tokenizers/base_tokenizer.py +++ b/griptape/tokenizers/base_tokenizer.py @@ -1,6 +1,6 @@ from __future__ import annotations import logging -from abc import ABC +from abc import ABC, abstractmethod from attrs import define, field, Factory @@ -40,6 +40,7 @@ def count_output_tokens_left(self, text: str) -> int: else: return 0 + @abstractmethod def count_tokens(self, text: str) -> int: ... def _default_max_input_tokens(self) -> int: diff --git a/griptape/utils/chat.py b/griptape/utils/chat.py index 12653ce9e8..f78d311f98 100644 --- a/griptape/utils/chat.py +++ b/griptape/utils/chat.py @@ -1,6 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional, Callable + +from typing import TYPE_CHECKING, Callable, Optional + from attrs import Factory, define, field + from griptape.utils.stream import Stream if TYPE_CHECKING: @@ -22,9 +25,9 @@ class Chat: def default_output_fn(self, text: str) -> None: if self.structure.config.prompt_driver.stream: - print(text, end="", flush=True) + print(text, end="", flush=True) # noqa T201 else: - print(text) + print(text) # noqa T201 def start(self) -> None: if self.intro_text: diff --git a/griptape/utils/dict_utils.py b/griptape/utils/dict_utils.py index 64a91d68bf..c5f6bb6764 100644 --- a/griptape/utils/dict_utils.py +++ b/griptape/utils/dict_utils.py @@ -30,7 +30,7 @@ def dict_merge(dct: dict, merge_dct: dict, add_keys: bool = True) -> dict: if not add_keys: merge_dct = {k: merge_dct[k] for k in set(dct).intersection(set(merge_dct))} - for key in merge_dct.keys(): + for key in merge_dct: if key in dct and isinstance(dct[key], dict): dct[key] = dict_merge(dct[key], merge_dct[key], add_keys=add_keys) else: diff --git a/griptape/utils/import_utils.py b/griptape/utils/import_utils.py index 5e00551f84..0de09b2d15 100644 --- a/griptape/utils/import_utils.py +++ b/griptape/utils/import_utils.py @@ -32,8 +32,8 @@ def import_optional_dependency(name: str) -> Optional[ModuleType]: ) try: module = import_module(name) - except ImportError: - raise ImportError(msg) + except ImportError as exc: + raise ImportError(msg) from exc return module diff --git a/griptape/utils/load_artifact_from_memory.py b/griptape/utils/load_artifact_from_memory.py index 6ab8231305..af11b8ae87 100644 --- a/griptape/utils/load_artifact_from_memory.py +++ b/griptape/utils/load_artifact_from_memory.py @@ -14,8 +14,8 @@ def load_artifact_from_memory( try: artifact = [a for a in artifacts if a.name == artifact_name][0] - except IndexError: - raise ValueError(f"artifact {artifact_name} not found in namespace {artifact_namespace}") + except IndexError as exc: + raise ValueError(f"artifact {artifact_name} not found in namespace {artifact_namespace}") from exc if not isinstance(artifact, artifact_type): raise ValueError(f"{artifact.name} is not of type {artifact_type}") diff --git a/pyproject.toml b/pyproject.toml index dc7cb78779..c1b6b934c6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -200,7 +200,22 @@ line-length = 120 skip-magic-trailing-comma = true [tool.ruff.lint] -select = ["E4", "E7", "E9", "F", "TID251"] +select = [ + "E", # pycodestyle + "F", # Pyflakes + "UP", # pyupgrade + "B", # flake8-bugbear + "SIM", # flake8-simplify + "TID251", # banned-api + "T201", # print +] +ignore = [ + "UP007", # non-pep604-annotation + "E501", # line-too-long + "B024", # abstract-base-class-without-abstract-method + "B009", # get-attr-with-constant + "B010", # set-attr-with-constant +] [tool.ruff.lint.flake8-tidy-imports.banned-api] "attr".msg = "The attr module is deprecated, use attrs instead." diff --git a/tests/utils/code_blocks.py b/tests/utils/code_blocks.py index 09a4695bac..9cfebb9877 100644 --- a/tests/utils/code_blocks.py +++ b/tests/utils/code_blocks.py @@ -1,3 +1,4 @@ +import logging import pathlib import textwrap @@ -13,7 +14,7 @@ def check_py_string(source: str) -> None: try: exec(source, {"__MODULE__": "__main__"}) except Exception: - print(source) + logging.info(source) raise