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

csp.Struct needs to deepcopy its default values #69

Closed
robambalu opened this issue Feb 12, 2024 · 0 comments · Fixed by #134
Closed

csp.Struct needs to deepcopy its default values #69

robambalu opened this issue Feb 12, 2024 · 0 comments · Fixed by #134
Assignees
Labels
type: bug Concrete, reproducible bugs

Comments

@robambalu
Copy link
Collaborator

robambalu commented Feb 12, 2024

Describe the bug
If a csp.Struct type is defined with a mutable default ( ie dict ), then all instances of that type will share the same default. Mutate it in one, will mutate for all. This is similar to the age-old python mutable default argument problem, but we have the ability to fix it by deepcopying defaults instead of shallow copying

To Reproduce


class S(csp.Struct):
    d : dict = {}

s1 = S()
s2 = S()

s2.d['a'] = 1
print(s1)
> S( d={'a': 1} )
@timkpaine timkpaine added the type: bug Concrete, reproducible bugs label Feb 12, 2024
@robambalu robambalu self-assigned this Mar 7, 2024
robambalu added a commit that referenced this issue Mar 7, 2024
…se other fixes that popped up along the way:

* Fix move semantics on python DialectGeneric impl
* Fix deepcopy call when passing a tuple argument ( was only extracting first element )
* Fix extremely subtle deepcopy bug where partially created PyStruct was getting GC cleaned

Signed-off-by: Ambalu, Robert <robert.ambalu@point72.com>
robambalu added a commit that referenced this issue Mar 7, 2024
fixes #69 - deepcopy struct default values on init.  Also includes th…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Concrete, reproducible bugs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants