Skip to content

Commit

Permalink
Move to keyword only arguments to improve readability
Browse files Browse the repository at this point in the history
New pylint allows you to seperately set a maximum number of total aguments
and a maximum number of positional arguments. This gave us lots of warnings
on the number of functions that had a confusingly high number of arguments.

Rather than just up the limit in pylintrc it seems like good practice to make
many of these arguments keyword only. This make code more clear, and more robust
as we go forward.
  • Loading branch information
julianstirling committed Sep 27, 2024
1 parent 9849998 commit e43401e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
1 change: 1 addition & 0 deletions nimble_build_system/cad/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def cut_w_pattern(body: cad.Body,
size_y: cad.DimensionDefinitionType,
padding_x: float,
padding_y: float,
*,
min_spacing: float = 0,
cut_depth: float = 10,
) -> 'cad.Body':
Expand Down
30 changes: 20 additions & 10 deletions nimble_build_system/cad/shelf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@


def create_shelf_for(device_id: str,
*,
assembly_key: str='Shelf',
position: tuple[float, float, float]=(0,0,0),
color: str='dodgerblue1',
Expand Down Expand Up @@ -75,10 +76,10 @@ def create_shelf_for(device_id: str,
kwargs = {}
return shelf_class(
device,
assembly_key,
position,
color,
rack_params,
assembly_key=assembly_key,
position=position,
color=color,
rack_params=rack_params,
**kwargs
)

Expand Down Expand Up @@ -127,6 +128,7 @@ class Shelf():

def __init__(self,
device: Device,
*,
assembly_key: str,
position: tuple[float, float, float],
color: str,
Expand Down Expand Up @@ -516,13 +518,18 @@ class StuffShelf(Shelf):
##TODO: Perhaps make a "dummy" device for "stuff"?
def __init__(self,
device: Device,
*,
assembly_key: str,
position: tuple[float, float, float],
color: str,
rack_params: RackParameters,
thin: bool=False):

super().__init__(device, assembly_key, position, color, rack_params)
super().__init__(device,
assembly_key=assembly_key,
position=position,
color=color,
rack_params=rack_params)
self.thin = thin

def generate_shelf_model(self) -> cadscript.Body:
Expand Down Expand Up @@ -551,7 +558,7 @@ def generate_shelf_model(self) -> cadscript.Body:
builder = ShelfBuilder(
self.height_in_u, width="broad", depth="standard", front_type="full"
)
builder.cut_opening("<Y", builder.inner_width, 4)
builder.cut_opening("<Y", builder.inner_width, offset_y=4)
builder.make_tray(sides="w-pattern", back="open")
builder.add_mounting_hole_to_bottom(x_pos=0, y_pos=35, base_thickness=4, hole_type="M3cs")
builder.add_mounting_hole_to_bottom(x_pos=0, y_pos=120, base_thickness=4, hole_type="M3cs")
Expand All @@ -569,7 +576,7 @@ def generate_shelf_model(self) -> cadscript.Body:
builder = ShelfBuilder(
self.height_in_u, width="standard", depth=119.5, front_type="full"
)
builder.cut_opening("<Y", builder.inner_width, 4)
builder.cut_opening("<Y", builder.inner_width, offset_y=4)
builder.make_tray(sides="w-pattern", back="open")
# add 2 mounting bars on the bottom plate
sketch = cadscript.make_sketch()
Expand Down Expand Up @@ -624,6 +631,7 @@ class AnkerShelf(Shelf):
"""
def __init__(self,
device: Device,
*,
assembly_key: str,
position: tuple[float, float, float],
color: str,
Expand All @@ -633,9 +641,11 @@ def __init__(self,
internal_height: float = 25,
front_cutout_width: float = 53):

#pylint: disable=too-many-arguments

super().__init__(device, assembly_key, position, color, rack_params)
super().__init__(device,
assembly_key=assembly_key,
position=position,
color=color,
rack_params=rack_params)
self.internal_width = internal_width
self.internal_depth = internal_depth
self.internal_height = internal_height
Expand Down
18 changes: 12 additions & 6 deletions nimble_build_system/cad/shelf_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ class ShelfBuilder:
def __init__(
self,
height_in_u: int,
width: Union[Literal["standard", "broad"], float],
depth: Union[Literal["standard"], float],
front_type: Literal["full", "open", "w-pattern", "slots"],
*,
width: Union[Literal["standard", "broad"], float] = "standard",
depth: Union[Literal["standard"], float] = "standard",
front_type: Literal["full", "open", "w-pattern", "slots"] = "full",
base_between_beam_walls: Literal["none", "front-open", "closed"] = "closed",
beam_wall_type: Literal["none", "standard", "ramp"] = "standard",
rack_params=None,
Expand Down Expand Up @@ -399,6 +400,7 @@ def cut_opening(
self,
face: str,
size_x: cad.DimensionDefinitionType,
*,
offset_y: float = 0,
size_y: Optional[cad.DimensionDefinitionType] = None,
depth: float = 999,
Expand All @@ -420,7 +422,8 @@ def add_mounting_hole_to_bottom(
x_pos: float,
y_pos: float,
base_thickness: float,
hole_type: Literal["M3cs", "M3-tightfit", "base-only"],
*,
hole_type: Literal["M3cs", "M3-tightfit", "base-only"] = "M3-tightfit",
base_diameter: float = 15,
) -> None:
"""
Expand All @@ -442,8 +445,9 @@ def add_mounting_hole_to_side(
self,
y_pos: float,
z_pos: float,
hole_type: Literal["M3-tightfit", "HDD"],
side: Literal["left", "right", "both"],
*,
hole_type: Literal["M3-tightfit", "HDD"] = "M3-tightfit",
side: Literal["left", "right", "both"] = "both",
base_diameter: float = 8,
) -> None:
"""
Expand Down Expand Up @@ -506,6 +510,7 @@ def add_cage(
internal_width: float,
internal_depth: float,
internal_height: float = 0,
*,
rear_cutout_width: float = 0,
add_ziptie_channels: bool = True,
):
Expand Down Expand Up @@ -587,6 +592,7 @@ def get_body(self) -> cad.Body:

def ziptie_shelf(
height_in_u: int,
*,
internal_width: Optional[float] = None,
internal_depth: Optional[float] = None,
internal_height: Optional[float] = None,
Expand Down
4 changes: 2 additions & 2 deletions py.pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ exclude-too-few-public-methods=
# R0901)
ignored-parents=

## CHANGED FOM DEFAULT: increased due to the way we are passing parameters
## CHANGED FOM DEFAULT: increased to allow lots of key word only-args
# Maximum number of arguments for function / method.
max-args=7
max-args=10

# Maximum number of attributes for a class (see R0902).
max-attributes=7
Expand Down

0 comments on commit e43401e

Please sign in to comment.