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

State defaults and factories #22

Open
JamesArruda opened this issue Jan 3, 2025 · 0 comments
Open

State defaults and factories #22

JamesArruda opened this issue Jan 3, 2025 · 0 comments
Labels
future Check back in the future

Comments

@JamesArruda
Copy link
Collaborator

States currently handle mutable default values by deepcopying everything. Even with default_factory, the factory function gets called once and the result is deepcopied.

This means tests like this pass:

class Cashier(UP.Actor):
    items_scanned = UP.State[list](default=[])

c1 = Cashier(...)
c2 = Cashier(...)
assert id(c1.items_scanned) != id(c2.items_scanned)

when you might expect that to be the behavior.

This is acceptable for now, as the resulting behavior is what one would expect or desire.

If a default factory is supposed to be random, or expected to do anything more than return empty mutable objects, then this ticket will be necessary.

@JamesArruda JamesArruda added the future Check back in the future label Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
future Check back in the future
Projects
None yet
Development

No branches or pull requests

1 participant