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

Prevent 'add_child' from overwriting the 'child' (raise error) #865

Open
nrathaus opened this issue Oct 4, 2023 · 1 comment
Open

Prevent 'add_child' from overwriting the 'child' (raise error) #865

nrathaus opened this issue Oct 4, 2023 · 1 comment

Comments

@nrathaus
Copy link
Contributor

nrathaus commented Oct 4, 2023

I think it is a good idea to change the code to this:

    def add_child(self, child):
        """
        Sets the parameter as the child of the node

        :return: the child node
        """
        if self.child is not None:
            raise ValueError("Child is being overwritten")

        self.child = child
        return self.child

Or similar, to prevent repeated add_child being called when 'self.child' is already set, thus losing the previous one

@tomato42
Copy link
Member

tomato42 commented Oct 4, 2023

why?
it wouldn't protect against setting the child directly, and in some complex decision graphs, it may be easier to first create a simple structure and then modify it in place...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants