Skip to content

gh-149083: Convert dataclasses.MISSING and dataclasses.KW_ONLY to sentinels#149086

Open
JelleZijlstra wants to merge 1 commit intopython:mainfrom
JelleZijlstra:datacls-missing
Open

gh-149083: Convert dataclasses.MISSING and dataclasses.KW_ONLY to sentinels#149086
JelleZijlstra wants to merge 1 commit intopython:mainfrom
JelleZijlstra:datacls-missing

Conversation

@JelleZijlstra
Copy link
Copy Markdown
Member

@JelleZijlstra JelleZijlstra commented Apr 28, 2026

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.

…to sentinels

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant