[Python-Dev] Issues with PEP 526 Variable Notation at the class level (original) (raw)
Nathaniel Smith njs at pobox.com
Fri Dec 8 21:14:58 EST 2017
- Previous message (by thread): [Python-Dev] Issues with PEP 526 Variable Notation at the class level
- Next message (by thread): [Python-Dev] Issues with PEP 526 Variable Notation at the class level
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Dec 7, 2017 12:49, "Eric V. Smith" <eric at trueblade.com> wrote:
The reason I didn't include it (as @dataclass(slots=True)) is because it has to return a new class, and the rest of the dataclass features just modifies the given class in place. I wanted to maintain that conceptual simplicity. But this might be a reason to abandon that. For what it's worth, attrs does have an @attr.s(slots=True) that returns a new class with slots set.
They actually switched to always returning a new class, regardless of whether slots is set:
https://github.com/python-attrs/attrs/pull/260
You'd have to ask Hynek to get the full rationale, but I believe it was both for consistency with slot classes, and for consistency with regular class definition. For example, type.new actually does different things depending on whether it sees an eq method, so adding a method after the fact led to weird bugs with hashing. That class of bug goes away if you always set up the autogenerated methods and then call type.new.
-n -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20171208/72139e92/attachment.html>
- Previous message (by thread): [Python-Dev] Issues with PEP 526 Variable Notation at the class level
- Next message (by thread): [Python-Dev] Issues with PEP 526 Variable Notation at the class level
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]