-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
Frozen dataclasses with slots raise TypeError #90055
Comments
When making a dataclass with slots=True and frozen=True, assigning to an invalid attribute raises a TypeError rather than a FrozenInstanceError: >>> from dataclasses import dataclass
>>> @dataclass(frozen=True, slots=True)
... class Vector:
... x: float
... y: float
... z: float
...
>>> v = Vector(1, 2, 3)
>>> v.a = 4
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 5, in __setattr__
TypeError: super(type, obj): obj must be an instance or subtype of type |
This looks to be due to the fact that I believe this can be fixed by tweaking |
I think the error should be AttributeError, which is what you'd get if the class weren't frozen. |
You get the same error if you subclass a frozen dataclass, then try to set an attribute that is not one of the superclass's __slots__:
|
It looks like this is not the approach you took, but to be clear, using |
Yes, this is why this is not the approach I took :) thanks for updating the issue though! I forgot that I'd left that comment |
Okay, I'm finally getting a chance to look at this. A few things:
|
I'm going to close this. If someone really feels strongly that the exception needs to change, please open a discussion on discuss.python.org. We can re-open this issue if a discussion there produces some consensus. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: