From c72f0d4bac1f8fb00f5ea51c70008539427df599 Mon Sep 17 00:00:00 2001 From: "sourcery-ai[bot]" <58596630+sourcery-ai[bot]@users.noreply.github.com> Date: Thu, 17 Mar 2022 19:31:53 -0400 Subject: [PATCH] 'Refactored by Sourcery' (#414) Co-authored-by: Sourcery AI <> --- gaphas/geometry.py | 2 +- gaphas/handlemove.py | 9 ++------- gaphas/item.py | 6 +++--- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/gaphas/geometry.py b/gaphas/geometry.py index fa68773a..0b220b98 100644 --- a/gaphas/geometry.py +++ b/gaphas/geometry.py @@ -320,7 +320,7 @@ def distance_rectangle_point(rect: Rect | Rectangle, point: Point) -> float: """Return the distance (fast) from a rectangle ``(x, y, width,height)`` to a ``point``.""" d = distance_rectangle_border_point(rect, point) - return 0 if d < 0 else d + return max(d, 0) def point_on_rectangle( diff --git a/gaphas/handlemove.py b/gaphas/handlemove.py index d30fc63b..0ee30c77 100644 --- a/gaphas/handlemove.py +++ b/gaphas/handlemove.py @@ -31,8 +31,7 @@ def start_move(self, pos: Pos) -> None: self.last_x, self.last_y = pos model = self.view.model assert model - cinfo = model.connections.get_connection(self.handle) - if cinfo: + if cinfo := model.connections.get_connection(self.handle): self.handle.glued = True model.connections.solver.remove_constraint(cinfo.constraint) @@ -102,11 +101,7 @@ def connect(self, pos: Pos) -> None: connections = model.connections connector = Connector(self.item, handle, connections) - # find connectable item and its port - sink = self.glue(pos) - - # no new connectable item, then diconnect and exit - if sink: + if sink := self.glue(pos): connector.connect(sink) else: cinfo = connections.get_connection(handle) diff --git a/gaphas/item.py b/gaphas/item.py index f02f1393..5785655d 100644 --- a/gaphas/item.py +++ b/gaphas/item.py @@ -363,10 +363,10 @@ def _update_ports(self) -> None: used when initializing the line. """ assert len(self._handles) >= 2, "Not enough segments" - self._ports = [] handles = self._handles - for h1, h2 in zip(handles[:-1], handles[1:]): - self._ports.append(LinePort(h1.pos, h2.pos)) + self._ports = [ + LinePort(h1.pos, h2.pos) for h1, h2 in zip(handles[:-1], handles[1:]) + ] def opposite(self, handle: Handle) -> Handle: """Given the handle of one end of the line, return the other end."""