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

field_provider.py mutable default argument #187

Merged
merged 2 commits into from
Sep 26, 2024

Conversation

SeaTechRC
Copy link
Contributor

Hello,

in the FieldProvider class, there are multiple instances of mutable default arguments.
I have observed, that when using the FieldFriend and creating a field, adding more than one row results in the rows sharing the same points until restarted.
The root cause are mutable default arguments (the list of points given when calling create_row as example), which are then referenced in 2 different instances of Row. When restarting the the program, the rows are restored from a file, in which case, the list of points are instantiated seperately (fixing this shared reference).

The fix is to simply change the function to explicitly create a new list, when no argument is supplied.

@pascalzauberzeug pascalzauberzeug added bug Something isn't working enhancement New feature or request and removed bug Something isn't working labels Sep 26, 2024
@pascalzauberzeug pascalzauberzeug added this to the 0.4.0 milestone Sep 26, 2024
Copy link
Contributor

@pascalzauberzeug pascalzauberzeug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SeaTechRC Thank you for the PR. You are totally correct, mutable defaults can lead to very nasty debugging sessions.
I will merge this now to keep the code safe, but we are currently reworking the whole class anyway.

@pascalzauberzeug pascalzauberzeug merged commit c7ca109 into zauberzeug:main Sep 26, 2024
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants