Skip to content

Commit

Permalink
Enable flake8-comprehensions ruff rule
Browse files Browse the repository at this point in the history
  • Loading branch information
collindutter committed Jul 12, 2024
1 parent b8f1128 commit 2ac68ce
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion griptape/artifacts/base_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def value_to_bytes(cls, value: Any) -> bytes:
def value_to_dict(cls, value: Any) -> dict:
dict_value = value if isinstance(value, dict) else json.loads(value)

return {k: v for k, v in dict_value.items()}
return dict(dict_value.items())

def to_text(self) -> str:
return str(self.value)
Expand Down
2 changes: 1 addition & 1 deletion griptape/drivers/file_manager/base_file_manager_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class BaseFileManagerDriver(ABC):
def list_files(self, path: str) -> TextArtifact | ErrorArtifact:
try:
entries = self.try_list_files(path)
return TextArtifact("\n".join([e for e in entries]))
return TextArtifact("\n".join(list(entries)))
except FileNotFoundError:
return ErrorArtifact("Path not found")
except NotADirectoryError:
Expand Down
4 changes: 2 additions & 2 deletions griptape/drivers/prompt/google_prompt_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def __to_prompt_stack_message_content(self, content: Part) -> BaseMessageContent

name, path = ToolAction.from_native_tool_name(function_call.name)

args = {k: v for k, v in function_call.args.items()}
args = dict(function_call.args.items())
return ActionCallMessageContent(
artifact=ActionArtifact(value=ToolAction(tag=function_call.name, name=name, path=path, input=args))
)
Expand All @@ -237,7 +237,7 @@ def __to_prompt_stack_delta_message_content(self, content: Part) -> BaseDeltaMes

name, path = ToolAction.from_native_tool_name(function_call.name)

args = {k: v for k, v in function_call.args.items()}
args = dict(function_call.args.items())
return ActionCallDeltaMessageContent(
tag=function_call.name, name=name, path=path, partial_input=json.dumps(args)
)
Expand Down
2 changes: 1 addition & 1 deletion griptape/drivers/sql/snowflake_sql_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def execute_query_raw(self, query: str) -> Optional[list[dict[str, Any]]]:

if results is not None:
if results.returns_rows:
return [{column: value for column, value in result.items()} for result in results]
return [dict(result.items()) for result in results]
else:
return None
else:
Expand Down
2 changes: 1 addition & 1 deletion griptape/drivers/sql/sql_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def execute_query_raw(self, query: str) -> Optional[list[dict[str, Optional[Any]

if results is not None:
if results.returns_rows:
return [{column: value for column, value in result.items()} for result in results]
return [dict(result.items()) for result in results]
else:
return None
else:
Expand Down
2 changes: 1 addition & 1 deletion griptape/tasks/actions_subtask.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def execute_actions(self, actions: list[ToolAction]) -> list[tuple[str, BaseArti
with self.futures_executor_fn() as executor:
results = utils.execute_futures_dict({a.tag: executor.submit(self.execute_action, a) for a in actions})

return [r for r in results.values()]
return list(results.values())

def execute_action(self, action: ToolAction) -> tuple[str, BaseArtifact]:
if action.tool is not None:
Expand Down
2 changes: 1 addition & 1 deletion griptape/tasks/image_query_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def image_query_engine(self, value: ImageQueryEngine) -> None:
def run(self) -> TextArtifact:
query = self.input.value[0]

if all([isinstance(input, ImageArtifact) for input in self.input.value[1:]]):
if all(isinstance(input, ImageArtifact) for input in self.input.value[1:]):
image_artifacts = [input for input in self.input.value[1:] if isinstance(input, ImageArtifact)]
else:
raise ValueError("All inputs after the query must be ImageArtifacts.")
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ select = [
"TCH", # flake8-type-checking
"D", # pydocstyle
"PGH", # pygrep-hooks
"I" # isort
"I", # isort
"C4" # flake8-comprehensions
]
ignore = [
"UP007", # non-pep604-annotation
Expand Down

0 comments on commit 2ac68ce

Please sign in to comment.