Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kwargs to classes with sensible default values #72

Open
lukethehuman opened this issue Sep 4, 2024 · 0 comments
Open

Add kwargs to classes with sensible default values #72

lukethehuman opened this issue Sep 4, 2024 · 0 comments
Labels
code quality documentation Improvements or additions to documentation

Comments

@lukethehuman
Copy link
Collaborator

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.

@lukethehuman lukethehuman added code quality documentation Improvements or additions to documentation labels Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant