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 option to define __dict__ on Struct type #331

Merged
merged 1 commit into from Feb 24, 2023
Merged

Conversation

jcrist
Copy link
Owner

@jcrist jcrist commented Feb 24, 2023

This adds a new dict option on a Struct type, disabled by default. Enabling this will add a lazily-allocated __dict__ attribute to all instances of that type, which can be used to store additional runtime state. Note that any data stored in the __dict__ is not encoded/decoded/pickled/copied by default.

One use of this is to support functools.cached_property on Struct instances, since this decorator stores the cached value on the instance __dict__.

Fixes #324, fixes #204.

This adds a new `dict` option on a `Struct` type, disabled by default.
Enabling this will add a lazily-allocated `__dict__` attribute to all
instances of that type, which can be used to store additional runtime
state. Note that any data stored in the `__dict__` is _not_
encoded/decoded/pickled/copied by default.

One use of this is to support `functools.cached_property` on `Struct`
instances, since this decorator stores the cached value on the instance
`__dict__`.
@jcrist jcrist merged commit 59b709d into main Feb 24, 2023
@jcrist jcrist deleted the add-struct-dict-option branch February 24, 2023 19:27
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

Successfully merging this pull request may close these issues.

Add option to add __dict__ on msgspec.Struct types functools.cached_property support?
1 participant