From e43401e406f83a84554af81631ceea6c2aaef622 Mon Sep 17 00:00:00 2001 From: Julian Stirling Date: Fri, 27 Sep 2024 11:24:06 +0100 Subject: [PATCH] Move to keyword only arguments to improve readability 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. --- nimble_build_system/cad/helpers.py | 1 + nimble_build_system/cad/shelf.py | 30 ++++++++++++++++-------- nimble_build_system/cad/shelf_builder.py | 18 +++++++++----- py.pylintrc | 4 ++-- 4 files changed, 35 insertions(+), 18 deletions(-) diff --git a/nimble_build_system/cad/helpers.py b/nimble_build_system/cad/helpers.py index c4750bb..ccdbb03 100644 --- a/nimble_build_system/cad/helpers.py +++ b/nimble_build_system/cad/helpers.py @@ -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': diff --git a/nimble_build_system/cad/shelf.py b/nimble_build_system/cad/shelf.py index b57d073..a14b20e 100644 --- a/nimble_build_system/cad/shelf.py +++ b/nimble_build_system/cad/shelf.py @@ -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', @@ -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 ) @@ -127,6 +128,7 @@ class Shelf(): def __init__(self, device: Device, + *, assembly_key: str, position: tuple[float, float, float], color: str, @@ -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: @@ -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(" cadscript.Body: builder = ShelfBuilder( self.height_in_u, width="standard", depth=119.5, front_type="full" ) - builder.cut_opening(" None: """ @@ -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: """ @@ -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, ): @@ -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, diff --git a/py.pylintrc b/py.pylintrc index a554116..a19fdc2 100644 --- a/py.pylintrc +++ b/py.pylintrc @@ -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