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

Immutable classes #50

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

Immutable classes #50

wants to merge 16 commits into from

Conversation

getzze
Copy link

@getzze getzze commented Sep 25, 2024

closes #35

REBASED TO #49

Uses the attrs package to create frozen classes.
The new instances are picklable in an incompatible way (unpickling old classes would not work).

As a bonus, the instances can be unstructured using cattrs.

This is a test PR, maybe it makes more sense to keep the old code and just forbid setting the attributes using properties.

@Diaoul
Copy link
Owner

Diaoul commented Sep 26, 2024

Thanks for the typing and work there! Should we stick to the stdlib and use dataclasses with frozen=True? My main concern is introducing a dependency on another package

@getzze
Copy link
Author

getzze commented Sep 26, 2024 via email

@getzze
Copy link
Author

getzze commented Sep 27, 2024

I struggled a bit with using __getattr__ and pickle without defining __setstate__, but I solved it finally.

It uses only the dataclasses stdlib now. I left cattrs as a test dependency, but maybe it's not worth it either, let me know what you think.

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.

Immutability issues
2 participants