From b98614ca5b154caf60a926c956f29db102867252 Mon Sep 17 00:00:00 2001 From: Christophe Bornet Date: Sun, 8 Dec 2024 12:05:07 +0100 Subject: [PATCH] ref: Apply ruff rules FURB110 and RUF046 (#5093) Apply rules FURB110 and RUF046 --- .../langflow/components/logic/flow_tool.py | 2 +- .../base/langflow/graph/graph/ascii.py | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/backend/base/langflow/components/logic/flow_tool.py b/src/backend/base/langflow/components/logic/flow_tool.py index 396a39192..a8655335d 100644 --- a/src/backend/base/langflow/components/logic/flow_tool.py +++ b/src/backend/base/langflow/components/logic/flow_tool.py @@ -93,7 +93,7 @@ class FlowToolComponent(LCToolComponent): except Exception: # noqa: BLE001 logger.opt(exception=True).warning("Failed to set run_id") inputs = get_flow_inputs(graph) - tool_description = self.tool_description.strip() if self.tool_description.strip() else flow_data.description + tool_description = self.tool_description.strip() or flow_data.description tool = FlowTool( name=self.tool_name, description=tool_description, diff --git a/src/backend/base/langflow/graph/graph/ascii.py b/src/backend/base/langflow/graph/graph/ascii.py index 93ebce8ec..2d7e0f196 100644 --- a/src/backend/base/langflow/graph/graph/ascii.py +++ b/src/backend/base/langflow/graph/graph/ascii.py @@ -90,11 +90,11 @@ class AsciiCanvas: self.point(x0, y0, char) elif abs(dx) >= abs(dy): for x in range(x0, x1 + 1): - y = y0 + int(round((x - x0) * dy / float(dx))) if dx else y0 + y = y0 + round((x - x0) * dy / float(dx)) if dx else y0 self.point(x, y, char) else: for y in range(min(y0, y1), max(y0, y1) + 1): - x = x0 + int(round((y - y0) * dx / float(dy))) if dy else x0 + x = x0 + round((y - y0) * dx / float(dy)) if dy else x0 self.point(x, y, char) def text(self, x, y, text) -> None: @@ -171,8 +171,8 @@ def draw_graph(vertexes, edges, *, return_ascii=True): maxx = max(xlist) maxy = max(ylist) - canvas_cols = int(math.ceil(maxx - minx)) + 1 - canvas_lines = int(round(maxy - miny)) + canvas_cols = math.ceil(maxx - minx) + 1 + canvas_lines = round(maxy - miny) canvas = AsciiCanvas(canvas_cols, canvas_lines) @@ -184,18 +184,18 @@ def draw_graph(vertexes, edges, *, return_ascii=True): start = edge.view._pts[index - 1] end = edge.view._pts[index] canvas.line( - int(round(start[0] - minx)), - int(round(start[1] - miny)), - int(round(end[0] - minx)), - int(round(end[1] - miny)), + round(start[0] - minx), + round(start[1] - miny), + round(end[0] - minx), + round(end[1] - miny), "*", ) for vertex in sug.g.sV: x = vertex.view.xy[0] - vertex.view.w / 2.0 y = vertex.view.xy[1] - canvas.box(int(round(x - minx)), int(round(y - miny)), vertex.view.w, vertex.view.h) - canvas.text(int(round(x - minx)) + 1, int(round(y - miny)) + 1, vertex.data) + canvas.box(round(x - minx), round(y - miny), vertex.view.w, vertex.view.h) + canvas.text(round(x - minx) + 1, round(y - miny) + 1, vertex.data) if return_ascii: return canvas.draws() canvas.draw()