Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable flake8-comprehensions ruff rule #977

Merged
merged 3 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion griptape/artifacts/base_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,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 @@ -230,7 +230,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 @@ -245,7 +245,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,
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 @@ -59,7 +59,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 = [
"PGH", # pygrep-hooks
"I", # isort
"FA", # flake8-future-annotations
"COM" # flake8-commas
"COM", # flake8-commas
"C4", # flake8-comprehensions
]
ignore = [
"UP007", # non-pep604-annotation
Expand Down
Loading