]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-149083: Convert dataclasses.MISSING and dataclasses.KW_ONLY to sentinels (#149086)
authorJelle Zijlstra <jelle.zijlstra@gmail.com>
Thu, 30 Apr 2026 02:39:29 +0000 (19:39 -0700)
committerGitHub <noreply@github.com>
Thu, 30 Apr 2026 02:39:29 +0000 (19:39 -0700)
commit16952218d0535904236e8a39851133688c9ce1f0
treed868f34525ae1df53276e5d037f6b58db4533bd8
parent8851a06e6e7ff23d91e5568df03a5ade570d4ab5
gh-149083: Convert dataclasses.MISSING and dataclasses.KW_ONLY to sentinels (#149086)

There were comments claiming these were implemented as custom classes to give a nicer
repr(), but the repr() wasn't all that nice:

>>> repr(dataclasses.MISSING)
'<dataclasses._MISSING_TYPE object at 0x1005e7e00>'
>>> repr(dataclasses.KW_ONLY)
'<dataclasses._KW_ONLY_TYPE object at 0x100884050>'

Sentinels are conceptually the right tool for these, so let's use them.

This does change the repr() of these two objects.
Lib/dataclasses.py
Lib/test/test_dataclasses/__init__.py
Misc/NEWS.d/next/Library/2026-04-27-20-15-54.gh-issue-149083.BdrpU8.rst [new file with mode: 0644]