Skip to content

Add kwargs to classes with sensible default values #72

@lukethehuman

Description

@lukethehuman

The init for GeometryMaker currently looks like this:

class GeometryMaker():
    def __init__(self) -> None:
        initialise_cubit()
        self.parameter_filler = ParameterFiller()
        self.materials_tracker = MaterialsTracker()
        self.component_tracker = ComponentTracker()
        self.design_tree = {}
        self.constructed_geometry = []
        self.print_parameter_logs = False
        self.track_components = track_components
        self.key_route_delimiter = '/'

Changing any of the settings requires an attribute override after instantiation, e.g.

maker = GeometryMaker()
maker.track_components = True

This is a little cumbersome for the end user, but also limits exposure of the options available to the user. It would be prefferable to be able to do e.g.

maker = GeometryMaker(track_components=True)

To allow for this, the init would look like this:

class GeometryMaker():
    """_summary_
    """

    def __init__(
        """_summary_

        Parameters
        ----------
        track_components : bool, optional
            _description_, by default False
        delimiter : str, optional
            _description_, by default "/"
        """        self,
        track_components: bool = False,
       delimiter: str = "/",
    ) -> None:
        initialise_cubit()
        self.parameter_filler = ParameterFiller()
        self.materials_tracker = MaterialsTracker()
        self.component_tracker = ComponentTracker()
        self.design_tree = {}
        self.constructed_geometry = []
        self.print_parameter_logs = False
        self.track_components = track_components
        self.key_route_delimiter = "/"

This should be repeated for all attributes of all classes where we expect the user (including other objects in the code which use a given object as users) may wish the change the setting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions