I'm much more interested in the typing community's feedback; runtime-wise I'm sure something will be doable. If this style is accepted I volunteer to write the runtime implementation. A tangent, since we're discussing implementation: I'm the person who initially contributed slot support to attrs, back in 2016 (phew), after which it went through several iterations by myself and other people before being ported to dataclasses. It's not possible to convert an existing dict class into a slot class so the class needs to be cloned, like you mentioned. But in attrs, cloned classes work with bare super on all Python versions we support (including PyPy) since we maintain the gnarly workaround code for it. In any case, I don't know yet if the `__mro__` of a class can be changed at runtime or if the class needs to be cloned. On Mon, May 9, 2022 at 2:18 AM Eric V. Smith <eric@trueblade.com> wrote:
On 5/8/2022 5:01 PM, David Hagen wrote:
I am sympathetic to this design. Right now, `Enum` rewrites that
`"quit"` value so that `Message.QUIT` is not actually equal to `"quit"`, but is actually an instance of `Message`. If the syntax of `Enum` was expanded to allow not just values, but classes, then `Move`, `Write`, and `ChangeColor` would have to be rebuilt to be subclasses of `Message`. I am not sure what all the implications of that would be. I remember there was hesitation toward having dataclasses add `__slots__` because it required rebuilding each class from scratch [1], but that was ultimately resolved in favor of rebuilding [2]. I have not heard any horror stories about dataclass slots, so maybe it's ok.
There are definitely some problems with returning a new class for slots=True.
For example, zero-argument super is broken: https://github.com/python/cpython/issues/90562
I'm sure there are others.
Eric
_______________________________________________ Typing-sig mailing list -- typing-sig@python.org To unsubscribe send an email to typing-sig-leave@python.org https://mail.python.org/mailman3/lists/typing-sig.python.org/ Member address: tinchester@gmail.com