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

edc: unfrozen dataclasses are hashble #407

Open
SobhanMP opened this issue Jul 19, 2023 · 2 comments
Open

edc: unfrozen dataclasses are hashble #407

SobhanMP opened this issue Jul 19, 2023 · 2 comments

Comments

@SobhanMP
Copy link

SobhanMP commented Jul 19, 2023

I think the general consensus in Python is that mutable types should not be hashable; however unfrozen dataclasses are hashable. See code below:

import dataclasses
from etils import edc
@edc.dataclass(allow_unfrozen=True)
@dataclasses.dataclass(eq=True, kw_only=True, frozen=True)
class Conf:
    x: int = 3
a = Conf()
a = a.unfrozen()
a.x = 2
hash(a) # should fail

ps. edc is really handy

@Conchylicultor
Copy link
Member

Sorry for the late answer, I somehow missed this issue.

Thank you for the feedback. I'm not sure about this one. Most python objects are hashable by default, including mutable ones.

a = object()
a.x = 2  # a is mutable
hash(a)  # Works

Is this an issue in practice ? Was there a failure you encounter because of this ? Otherwise I'll be in favour of keeping the default. It is sometimes convenient to use the default identity based hash, though I understand in this specific case, this could be confusing.

@SobhanMP
Copy link
Author

It's not really an issue, but I imagine it makes for an easy-to-make error for jitted jax functions.

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

No branches or pull requests

2 participants