bpo-36077: Update handling of defaulted fields by EpicWink · Pull Request #17322 · python/cpython

Conversation

@EpicWink

When a non-defaulted dataclass field follows a defaulted field, the behaviour has changed from raising a TypeError to making all arguments in __init__ following the defaulted field keyword-only.

I'm not sold on the prettiness of the versionchanged area in the docs change: please comment.

https://bugs.python.org/issue36077

lucmos, borgstrom, jdlourenco, glestaris, shahabejaz, luizribeiro, jonashaag, gromsterus, ZackerySpytz, ZdenekM, and 12 more reacted with thumbs up emoji intgr, NeilGirdhar, qdamian, meoril, jobh, renzenicolai, guilhermelou, and krassowski reacted with heart emoji lucmos and guilhermelou reacted with rocket emoji
When a non-defaulted dataclass field follows a defaulted field, the
behaviour has changed from raising a `TypeError` to making all arguments
in `__init__` following the defaulted field keyword-only.

@jdlourenco

@EpicWink

@ericvsmith

We don't typically update PEPs when new features are added.

@EpicWink

Other way around: this pull-request is in direct contradiction with the PEP (it says that non-defaulted fields following defaulted fields cause a TypeError)

@ericvsmith

It doesn't matter: PEPs are not meant to describe current behavior.

@EpicWink

@NeilGirdhar

This is so useful! Thanks for the patch.

@randallpittman

Thank you for the patch. Any way to know if this will get into 3.10?

@EpicWink

@ericvsmith

@EpicWink

This has been superseded by the more explicit solution to be included in Python 3.10 #24909

Labels