Skip to content

Commit

Permalink
Merge pull request #387 from fischman/pylint
Browse files Browse the repository at this point in the history
De-lint topology.py, joints.py, and operations_part.py
  • Loading branch information
gumyr authored Nov 22, 2023
2 parents 4015c9f + 8f6c11e commit fb6f474
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
9 changes: 5 additions & 4 deletions src/build123d/operations_part.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
def extrude(
to_extrude: Union[Face, Sketch] = None,
amount: float = None,
dir: VectorLike = None,
dir: VectorLike = None, # pylint: disable=redefined-builtin
until: Until = None,
target: Union[Compound, Solid] = None,
both: bool = False,
Expand Down Expand Up @@ -80,7 +80,7 @@ def extrude(
Returns:
Part: extruded object
"""
# pylint: disable=too-many-locals
# pylint: disable=too-many-locals, too-many-branches
context: BuildPart = BuildPart._get_context("extrude")
validate_inputs(context, "extrude", to_extrude)

Expand Down Expand Up @@ -264,6 +264,7 @@ def make_brake_formed(
Returns:
Part: sheet metal part
"""
# pylint: disable=too-many-locals, too-many-branches
context: BuildPart = BuildPart._get_context("make_brake_formed")
validate_inputs(context, "make_brake_formed")

Expand All @@ -283,8 +284,8 @@ def make_brake_formed(

try:
plane = Plane(Face.make_from_wires(offset_line))
except:
raise ValueError("line not suitable - probably straight")
except Exception as exc:
raise ValueError("line not suitable - probably straight") from exc

# Make edge pairs
station_edges = ShapeList()
Expand Down
28 changes: 21 additions & 7 deletions src/build123d/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
# too-many-statements, too-many-instance-attributes, too-many-branches
import copy
import itertools
import logging
import os
import platform
import sys
Expand Down Expand Up @@ -564,6 +563,7 @@ def common_plane(self, *lines: Union[Edge, Wire]) -> Union[None, Plane]:
Returns:
Union[None, Plane]: Either the common plane or None
"""
# pylint: disable=too-many-locals
# BRepLib_FindSurface could help here
points: list[Vector] = []
all_lines: list[Edge, Wire] = [
Expand Down Expand Up @@ -816,6 +816,7 @@ def offset_2d(
Returns:
Wire: offset wire
"""
# pylint: disable=too-many-branches, too-many-locals, too-many-statements
kind_dict = {
Kind.ARC: GeomAbs_JoinType.GeomAbs_Arc,
Kind.INTERSECTION: GeomAbs_JoinType.GeomAbs_Intersection,
Expand Down Expand Up @@ -1391,6 +1392,7 @@ class Shape(NodeMixin):
topo_parent (Shape): assembly parent of this object
"""
# pylint: disable=too-many-instance-attributes, too-many-public-methods

_dim = None

Expand Down Expand Up @@ -1763,7 +1765,7 @@ def clean(self) -> Self:
try:
upgrader.Build()
self.wrapped = downcast(upgrader.Shape())
except:
except: # pylint: disable=bare-except
warnings.warn(f"Unable to clean {self}")
return self

Expand Down Expand Up @@ -2573,6 +2575,7 @@ def intersect(self, *to_intersect: Union[Shape, Axis, Plane]) -> Shape:
Returns:
Shape: Resulting object may be of a different class than self
"""
# pylint: disable=too-many-branches

# def ocp_section(this: Shape, that: Shape) -> (list[Vertex], list[Edge]):
# # Create a BRepAlgoAPI_Section object
Expand Down Expand Up @@ -3039,6 +3042,7 @@ def project_faces(
The projected faces
"""
# pylint: disable=too-many-locals
path_length = path.length
# The derived classes of Shape implement center
shape_center = self.center() # pylint: disable=no-member
Expand Down Expand Up @@ -3254,6 +3258,7 @@ def __call__(self, shape: Shape) -> bool:

class ShapeList(list[T]):
"""Subclass of list with custom filter and sort methods appropriate to CAD"""
# pylint: disable=too-many-public-methods

@property
def first(self) -> T:
Expand Down Expand Up @@ -3977,6 +3982,7 @@ def make_text(
)
"""
# pylint: disable=too-many-locals

def position_face(orig_face: "Face") -> "Face":
"""
Expand Down Expand Up @@ -4239,6 +4245,7 @@ def wires(self) -> list[Wire]:

class Edge(Mixin1D, Shape):
"""A trimmed curve that represents the border of a face"""
# pylint: disable=too-many-public-methods

_dim = 1

Expand Down Expand Up @@ -4683,6 +4690,7 @@ def make_spline(
Returns:
Edge: the spline
"""
# pylint: disable=too-many-locals
points = [Vector(point) for point in points]
if tangents:
tangents = tuple(Vector(v) for v in tangents)
Expand Down Expand Up @@ -4874,6 +4882,7 @@ def make_helix(
Returns:
Wire: helix
"""
# pylint: disable=too-many-locals
# 1. build underlying cylindrical/conical surface
if angle == 0.0:
geom_surf: Geom_Surface = Geom_CylindricalSurface(
Expand Down Expand Up @@ -4991,6 +5000,7 @@ def to_axis(self) -> Axis:

class Face(Shape):
"""a bounded surface that represents part of the boundary of a solid"""
# pylint: disable=too-many-public-methods

_dim = 2

Expand Down Expand Up @@ -5431,6 +5441,7 @@ def make_surface(
Returns:
Face: Potentially non-planar face
"""
# pylint: disable=too-many-branches
if surface_points:
surface_points = [Vector(p) for p in surface_points]
else:
Expand Down Expand Up @@ -6050,7 +6061,7 @@ def extrude_taper(
Returns:
Solid: extruded cross section
"""

# pylint: disable=too-many-locals
direction = Vector(direction)

if (
Expand Down Expand Up @@ -6264,7 +6275,7 @@ def extrude_until(
.solids()
.sort_by(direction_axis)[0]
)
except:
except: # pylint: disable=bare-except
warnings.warn("clipping error - extrusion may be incorrect")
else:
extrusion_parts = [extrusion.intersect(target_object)]
Expand All @@ -6275,7 +6286,7 @@ def extrude_until(
.solids()
.sort_by(direction_axis)[0]
)
except:
except: # pylint: disable=bare-except
warnings.warn("clipping error - extrusion may be incorrect")
extrusion = Shape.fuse(*extrusion_parts)

Expand Down Expand Up @@ -6758,6 +6769,7 @@ def trim(self, start: float, end: float) -> Wire:
Returns:
Wire: trimmed wire
"""
# pylint: disable=too-many-branches
if start >= end:
raise ValueError("start must be less than end")

Expand Down Expand Up @@ -7073,6 +7085,7 @@ def make_convex_hull(cls, edges: Iterable[Edge], tolerance: float = 1e-3) -> Wir
Returns:
Wire: convex hull perimeter
"""
# pylint: disable=too-many-branches, too-many-locals
# Algorithm:
# 1) create a cloud of points along all edges
# 2) create a convex hull which returns facets/simplices as pairs of point indices
Expand Down Expand Up @@ -7202,6 +7215,7 @@ def project_to_shape(
ValueError: Only one of direction or center must be provided
"""
# pylint: disable=too-many-branches
if not (direction is None) ^ (center is None):
raise ValueError("One of either direction or center must be provided")
if direction is not None:
Expand Down Expand Up @@ -7303,12 +7317,12 @@ def _connect_to(self, other: Joint, **kwargs): # pragma: no cover
self.connected_to = other

@abstractmethod
def connect_to(self, other: Joint, **kwargs):
def connect_to(self, other: Joint):
"""All derived classes must provide a connect_to method"""
raise NotImplementedError

@abstractmethod
def relative_to(self, other: Joint, *args, **kwargs) -> Location:
def relative_to(self, other: Joint) -> Location:
"""Return relative location to another joint"""
raise NotImplementedError

Expand Down

0 comments on commit fb6f474

Please sign in to comment.