I would like to do evil and nasty things with my dataclasses: inherit and 
extend them. In particular, I want to allow non-defaulted fields (ie required 
parameters to `__init__`) to be specified after defaulted fields (ie optional 
parameters), specifically in sub-classes (both parent and children are usable 
dataclasses). This is simply to reduce re-definition of fields between similar 
types (I wasn't able to come up with an elegant design using composition for my 
use-case).

The technical problem with allowing this currently is that we can't have 
required positional arguments after optional arguments in the dataclass's 
`__init__`, but I have a PR which will make those required arguments 
keyword-only.

I did some searching, but I wasn't able to find much discussion on this 
decision in the initial implementation of `dataclasses`.

Bug tracker: https://bugs.python.org/issue36077

GitHub PR: https://github.com/python/cpython/pull/17322

Discourse link (currently void of discussion): 
https://discuss.python.org/t/make-succeeding-non-default-init-parameters-keyword-only-in-dataclasses-instead-of-raising/2952

Laurie
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/2V2SCUFMK7PK3DVA7D77AVXWIXNTSQDK/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to