28 Sep
2019
28 Sep
'19
3:41 a.m.
On Fri, Sep 27, 2019, at 12:48, Andrew Barnert via Python-ideas wrote:
or get rid of the guarantee that @dataclass returns your class with extra dunders.
Why is dataclass a decorator instead of a metaclass (or, as below, pseudo-metaclass) anyway? Is it just that the decorator syntax looks nicer? If it were a metaclass, it could add __slots__ before constructing the class. def slot_dataclass(name, bases, dct): dct['__slots__'] = dct['__annotations__'].keys() return dataclasses.dataclass(type(name, bases, dct)) If the problem is that the metaclass syntax is ugly, maybe we need a nicer-looking metaclass syntax, e.g. "class MyClass(bases) as slot_dataclass:"