-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Crash when overriding field as property/method on frozen derived class #8334
Comments
Is there any workaround that would make this less of a crash but more of a warning ? warning that could therefore be ignore just like the others ones ? It's so sad no being able to properly override inherited properties with |
In #8976 there was a similar-looking crash when overriding a frozen attribute with a method: from dataclasses import dataclass
@dataclass(frozen=True)
class Foo:
attr: int
@dataclass(frozen=True)
class Bar(Foo):
def attr(self) -> int:
return 1 |
Isn't this related to #13475 ? Well I guess not completely, as for a frozen dataclass, a read-only property should be enough |
This pull request: 1. Fixes python#8334. Overriding a dataclass attribute with a method or property now results in an error message, not a crash. (Overriding an attribute with a non-attribute at runtime will result in either inconsistent behavior or an exception, so I think unconditionally disallowing this is fine.) 2. Makes mypy report an error if you try subclassing a frozen dataclass with a non-frozen one or vice versa. Attempting to do this subclassing at runtime will raise a TypeError.
This pull request: 1. Fixes #8334. Overriding a dataclass attribute with a method or property now results in an error message, not a crash. (Overriding an attribute with a non-attribute at runtime will result in either inconsistent behavior or an exception, so I think unconditionally disallowing this is fine.) 2. Makes mypy report an error if you try subclassing a frozen dataclass with a non-frozen one or vice versa. Attempting to do this subclassing at runtime will raise a TypeError.
I see this on python/mypy master (41b40aa) and Python 3.7.5.
Following on from #7535 (fixed recently by @msullivan), this triggers another crash (really just adding the
frozen=True
from my example on that bug report, though I also dropped the args tofield
since I realised I could):Traceback (seems slightly different from #6715 -- the assertion here is in method _freeze, not method collect_attributes):
The text was updated successfully, but these errors were encountered: