[issue46382] dataclass(slots=True) does not account for slots in base classes

2022-03-19 Thread Eric V. Smith
Eric V. Smith added the comment: Thanks for all of your work, @ariebovenberg! -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker

[issue46382] dataclass(slots=True) does not account for slots in base classes

2022-03-19 Thread Eric V. Smith
Eric V. Smith added the comment: New changeset 82e9b0bb0ac44d4942b9e01b2cdd2ca85c17e563 by Arie Bovenberg in branch 'main': bpo-46382 dataclass(slots=True) now takes inherited slots into account (GH-31980) https://github.com/python/cpython/commit/82e9b0bb0ac44d4942b9e01b2cdd2ca85c17e563

[issue46382] dataclass(slots=True) does not account for slots in base classes

2022-03-18 Thread Arie Bovenberg
Change by Arie Bovenberg : -- keywords: +patch pull_requests: +30070 stage: -> patch review pull_request: https://github.com/python/cpython/pull/31980 ___ Python tracker ___

[issue46382] dataclass(slots=True) does not account for slots in base classes

2022-03-18 Thread Eric V. Smith
Eric V. Smith added the comment: I thought there was an existing issue that covered this, but now I can't find it. I'd prefer #2, create a separate issue. -- ___ Python tracker

[issue46382] dataclass(slots=True) does not account for slots in base classes

2022-03-18 Thread Arie Bovenberg
Arie Bovenberg added the comment: @eric.smith awesome! What would you like to do about the __weakref__ slot? 1. take no action 2. create a separate ticket to discuss further 3. implement as done in attrs, now that we're changing __slots__ dataclass behavior anyway I wouldn't recommend

[issue46382] dataclass(slots=True) does not account for slots in base classes

2022-03-17 Thread Eric V. Smith
Eric V. Smith added the comment: I don't have a problem saying that for a class to be used as a base class for a dataclass, its __slots__ must not be an iterator that's been exhausted. That doesn't seem like a very onerous requirement. I'm also not concerned about people using __slots__ to

[issue46382] dataclass(slots=True) does not account for slots in base classes

2022-03-17 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Sorry, the previous message was written via a phone because of blackout, so the formatting is a tine bit messy. __slotnames__ is set in copyreg._slotnames(). If you want to keep a list of all slots you should save it in __slotnames__, either using

[issue46382] dataclass(slots=True) does not account for slots in base classes

2022-03-17 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: > > It is not set automatically. It is set in object.__reduce__ by calling > some helper function from the copyreg module. -- ___ Python tracker

[issue46382] dataclass(slots=True) does not account for slots in base classes

2022-03-17 Thread Eric V. Smith
Eric V. Smith added the comment: Serhiy: Could you point to some documentation on __slotnames__? I see a few references in the code to it, but it's not set on simple test class. >>> class A: ... __slots__=('a',) ... >>> A.__slotnames__ Traceback (most recent call last): File "", line

[issue46382] dataclass(slots=True) does not account for slots in base classes

2022-03-17 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: __slotnames__ is used for storing all slot names. New object.__getstate__() proposed in issue26579 may have some relation to this discussion. -- nosy: +serhiy.storchaka ___ Python tracker

[issue46382] dataclass(slots=True) does not account for slots in base classes

2022-03-17 Thread Arie Bovenberg
Arie Bovenberg added the comment: @eric.smith did you give this some thought? Would we want to imitate the attrs behavior regarding __weafref__? It'd be nice if I can submit a PR to be included in 3.11 -- ___ Python tracker

[issue46382] dataclass(slots=True) does not account for slots in base classes

2022-01-20 Thread Arie Bovenberg
Arie Bovenberg added the comment: @hynek interesting! The discussion in https://github.com/python-attrs/attrs/pull/420 on the weakref slot is very interesting as well. Considering __weakref__ is something we don't want to make impossible in dataclasses, @eric.smith what would be your

[issue46382] dataclass(slots=True) does not account for slots in base classes

2022-01-17 Thread Hynek Schlawack
Hynek Schlawack added the comment: >>> @attrs.define ... class C(Base): ... a: int ... b: int ... >>> C.__slots__ ('b', '__weakref__') We've got a test specifically for this use case:

[issue46382] dataclass(slots=True) does not account for slots in base classes

2022-01-17 Thread Alex Waygood
Change by Alex Waygood : -- nosy: +hynek ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue46382] dataclass(slots=True) does not account for slots in base classes

2022-01-17 Thread Eric V. Smith
Eric V. Smith added the comment: It would also be interesting to see what attrs does in this case. -- ___ Python tracker ___ ___

[issue46382] dataclass(slots=True) does not account for slots in base classes

2022-01-15 Thread Arie Bovenberg
Arie Bovenberg added the comment: Spencer is correct. The documentation even adds: "This renders the meaning of the program undefined." It's clear it doesn't break anything users would often encounter (we would have heard about it), but it's still undefined behavior. --

[issue46382] dataclass(slots=True) does not account for slots in base classes

2022-01-15 Thread Alex Waygood
Change by Alex Waygood : -- nosy: +AlexWaygood ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue46382] dataclass(slots=True) does not account for slots in base classes

2022-01-15 Thread Spencer Brown
Spencer Brown added the comment: Both will function, but class B will add its slots after A's, causing there to be an extra unused slot in the object that you can only access by directly using the A.a descriptor. So all slotted inheriting dataclasses cause the object to use more memory than

[issue46382] dataclass(slots=True) does not account for slots in base classes

2022-01-15 Thread Nikita Sobolev
Nikita Sobolev added the comment: Arie, can you please explain what is the technical difference between these two cases: ```python class A: __slots__ = ('a', ) # fields class B(A): __slots__ = ('a', 'b') # fields ``` And: ```python class C: __slots__ = ('a', ) #

[issue46382] dataclass(slots=True) does not account for slots in base classes

2022-01-14 Thread Arie Bovenberg
Arie Bovenberg added the comment: There are already 2 complexities I can think of: 1. This behavior may break some people's code, if they use __slots__ to iterate over the fields of a dataclass. Solution: explicitly mention in the docs that not every field may get a slot on the new

[issue46382] dataclass(slots=True) does not account for slots in base classes

2022-01-14 Thread Eric V. Smith
Eric V. Smith added the comment: I'll have to do some more research. But your analysis looks correct to me, so far. -- assignee: -> eric.smith nosy: +eric.smith ___ Python tracker

[issue46382] dataclass(slots=True) does not account for slots in base classes

2022-01-14 Thread Arie Bovenberg
New submission from Arie Bovenberg : @dataclass(slots=True) adds slots to dataclasses. It adds a slot per field. However, it doesn't account for slots already present in base classes: >>> class Base: ... __slots__ = ('a', ) ... >>> @dataclass(slots=True) ... class Foo(Base): ... a: