On 9/10/2017 10:00 AM, Michel Desmoulin wrote:
- any chance it becomes a built in later ? When classes have been
improved in Python 2, the object built-in was added. Imagine if we had
had to import it every time... Or maybe just plug it to object like
@object.dataclass.
Because of the choice of using module-level functions so as to not introduce conflicts in the object's namespace, it would be difficult to make this a builtin.
Although now that I think about it, maybe what are currently module-level functions should instead be methods on the "dataclass" decorator itself:
@dataclass
class C:
i: int = dataclass.field(default=1, init=False)
j: str
c = C('hello')
dataclass.asdict(c)
{'i': 1, 'j': 'hello'}
Then, "dataclass" would be the only name the module exports, making it easier to someday be a builtin. I'm not sure it's important enough for this to be a builtin, but this would make it easier. Thoughts? I'm usually not a fan of having attributes on a function: it's why itertools.chain.from_iterable() is hard to find.