Skip to content

Commit

Permalink
Merge pull request #78 from hbmartin/deepsource-autofix-1d96ba5d
Browse files Browse the repository at this point in the history
refactor: refactor unnecessary `else` / `elif` when `if` block has a `return` statement
  • Loading branch information
hbmartin authored Jul 3, 2024
2 parents bc43c9d + 79cd58b commit 8a93b33
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 49 deletions.
14 changes: 6 additions & 8 deletions graphviz2drawio/models/Rect.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@ def __init__(self, x, y, width, height) -> None:
def x_ratio(self, search):
if search < self.x:
return 0
elif search > self.x + self.width:
if search > self.x + self.width:
return 1
else:
ratio = (search - self.x) / self.width
return self._approx(ratio, 0.5, 0.1)
ratio = (search - self.x) / self.width
return self._approx(ratio, 0.5, 0.1)

def y_ratio(self, search):
if search < self.y:
return 0
elif search > self.y + self.height:
if search > self.y + self.height:
return 1
else:
ratio = (search - self.y) / self.height
return self._approx(ratio, 0.5, 0.1)
ratio = (search - self.y) / self.height
return self._approx(ratio, 0.5, 0.1)

@staticmethod
def _approx(value, center, delta):
Expand Down
3 changes: 1 addition & 2 deletions graphviz2drawio/mx/Edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ def __init__(
def curve_start_end(self):
if self.dir == DotAttr.BACK:
return self.curve.end, self.curve.start
else:
return self.curve.start, self.curve.end
return self.curve.start, self.curve.end

@property
def key_for_label(self) -> str:
Expand Down
6 changes: 2 additions & 4 deletions graphviz2drawio/mx/LinearRegression.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ def determination(points, y_mean, b0, b1) -> float:
sst.append(diff**2)
if sum(sst) == 0:
return 1 # Horizontal line
else:
return 1 - (sum(sse) / sum(sst))
return 1 - (sum(sse) / sum(sst))


def coefficients(points: list) -> list[float]:
Expand All @@ -44,5 +43,4 @@ def coefficients(points: list) -> list[float]:
b0 = m.imag - b1 * m.real
r2 = determination(points, m.imag, b0, b1)
return [b0, b1, r2]
else:
return [0, 0, 1] # Vertical line
return [0, 0, 1] # Vertical line
3 changes: 1 addition & 2 deletions graphviz2drawio/mx/MxGraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ def add_edge(self, edge) -> None:
def get_edge_source_target(self, edge):
if edge.dir == DotAttr.BACK:
return self.nodes[edge.to], self.nodes[edge.fr]
else:
return self.nodes[edge.fr], self.nodes[edge.to]
return self.nodes[edge.fr], self.nodes[edge.to]

@staticmethod
def get_edge_style(edge, source_node, target_node):
Expand Down
65 changes: 32 additions & 33 deletions graphviz2drawio/mx/Styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,70 +72,69 @@ class Styles(Enum):
def get_for_shape(dot_shape):
if dot_shape in (None, Shape.ELLIPSE, Shape.OVAL):
return Styles.ELLIPSE
elif dot_shape in (Shape.BOX, Shape.RECT, Shape.RECTANGLE):
if dot_shape in (Shape.BOX, Shape.RECT, Shape.RECTANGLE):
return Styles.NODE
elif dot_shape in (Shape.HEXAGON, Shape.POLYGON):
if dot_shape in (Shape.HEXAGON, Shape.POLYGON):
return Styles.HEXAGON
elif dot_shape == Shape.CIRCLE:
if dot_shape == Shape.CIRCLE:
return Styles.CIRCLE
elif dot_shape == Shape.EGG:
if dot_shape == Shape.EGG:
return Styles.EGG
elif dot_shape == Shape.TRIANGLE:
if dot_shape == Shape.TRIANGLE:
return Styles.TRIANGLE
elif dot_shape == Shape.PLAIN:
if dot_shape == Shape.PLAIN:
return Styles.LINE
elif dot_shape == Shape.DIAMOND:
if dot_shape == Shape.DIAMOND:
return Styles.DIAMOND
elif dot_shape == Shape.TRAPEZIUM:
if dot_shape == Shape.TRAPEZIUM:
return Styles.TRAPEZOID
elif dot_shape == Shape.PARALLELOGRAM:
if dot_shape == Shape.PARALLELOGRAM:
return Styles.PARALLELOGRAM
elif dot_shape == Shape.HOUSE:
if dot_shape == Shape.HOUSE:
return Styles.HOUSE
elif dot_shape == Shape.PENTAGON:
if dot_shape == Shape.PENTAGON:
return Styles.PENTAGON
elif dot_shape == Shape.OCTAGON:
if dot_shape == Shape.OCTAGON:
return Styles.OCTAGON
elif dot_shape == Shape.DOUBLE_CIRCLE:
if dot_shape == Shape.DOUBLE_CIRCLE:
return Styles.DOUBLE_CIRCLE
elif dot_shape == Shape.DOUBLE_OCTAGON:
if dot_shape == Shape.DOUBLE_OCTAGON:
return Styles.DOUBLE_OCTAGON
elif dot_shape == Shape.INV_TRIANGLE:
if dot_shape == Shape.INV_TRIANGLE:
return Styles.INV_TRIANGLE
elif dot_shape == Shape.INV_TRAPEZIUM:
if dot_shape == Shape.INV_TRAPEZIUM:
return Styles.INV_TRAPEZOID
elif dot_shape == Shape.INV_HOUSE:
if dot_shape == Shape.INV_HOUSE:
return Styles.INV_HOUSE
elif dot_shape == Shape.SQUARE:
if dot_shape == Shape.SQUARE:
return Styles.SQUARE
elif dot_shape == Shape.STAR:
if dot_shape == Shape.STAR:
return Styles.STAR
elif dot_shape == Shape.UNDERLINE:
if dot_shape == Shape.UNDERLINE:
return Styles.UNDERLINE
elif dot_shape == Shape.CYLINDER:
if dot_shape == Shape.CYLINDER:
return Styles.CYLINDER
elif dot_shape == Shape.NOTE:
if dot_shape == Shape.NOTE:
return Styles.NODE
elif dot_shape == Shape.TAB:
if dot_shape == Shape.TAB:
return Styles.TAB
elif dot_shape == Shape.FOLDER:
if dot_shape == Shape.FOLDER:
return Styles.FOLDER
elif dot_shape == Shape.BOX_3D:
if dot_shape == Shape.BOX_3D:
return Styles.CUBE
elif dot_shape == Shape.COMPONENT:
if dot_shape == Shape.COMPONENT:
return Styles.COMPONENT
elif dot_shape in (Shape.PROMOTER, Shape.RPROMOTER):
if dot_shape in (Shape.PROMOTER, Shape.RPROMOTER):
return Styles.RPROMOTER
elif dot_shape == Shape.LPROMOTER:
if dot_shape == Shape.LPROMOTER:
return Styles.LPROMOTER
elif dot_shape == Shape.CDS:
if dot_shape == Shape.CDS:
return Styles.CDS
elif dot_shape == Shape.RARROW:
if dot_shape == Shape.RARROW:
return Styles.RARROW
elif dot_shape == Shape.LARROW:
if dot_shape == Shape.LARROW:
return Styles.LARROW
else:
return Styles.NODE
return Styles.NODE

def format(self, **values):
return self.value.format(**values)

0 comments on commit 8a93b33

Please sign in to comment.