On Tue, Jan 21, 2020 at 12:55 PM
Currently, there is no way to add docstrings to fields in dataclasses. PEP257 talks about attribute docstrings (a string literal following an assignment), but these are visual only and not accessible at runtime. My suggestion would be a simple `doc` or `docstring` parameter to dataclasses.field(). Currently the best way to get anything close to this is using metadata, which is much clunkier: `dataclasses.field(metadata={'docstring': 'my description'})`
My first thought is "sure, why not", but then I thought a bit more, and I"m not so sure. docstrings are VERY useful for class methods. but dataclass fields are not methods, they are attributes, and usually simple attributes. Which I do'nt hink there is any way to attach docstrings to in regular old classes. You can crate a property that looks like an attribute, an give it a docstring, but if you're going that far, maybe dataclasses aren't the right tool for the job. In fact, I'm not sure it's even possible: if a filed is a simple type, say and in integer, how would you give it a a docstring?? In [17]: i.__doc__ = "an integer's docstring" --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-17-94dacc7686e2> in <module> ----> 1 i.__doc__ = "an integer's docstring" AttributeError: 'int' object attribute '__doc__' is read-only -CHB -- Christopher Barker, PhD Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython