Skip to content

Simplify Placeholder with the new sentinel() class - #161031

Closed
rhettinger wants to merge 2 commits into
python:mainfrom
rhettinger:placeholder_sentinel
Closed

rhettinger wants to merge 2 commits into
python:mainfrom
rhettinger:placeholder_sentinel

Conversation

@rhettinger

Copy link
Copy Markdown
Contributor

Minor code simplification courtesy of the new sentinel() builtin.

Comment thread Lib/functools.py
return 'Placeholder'

Placeholder = _PlaceholderType()
Placeholder = sentinel('Placeholder') # _PlaceholderType()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you want to retain pickability but I'm not sure that way works (I think you need to add the "functools." part for the module).

cc @JelleZijlstra

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this? Placeholder = sentinel('functools.Placeholder', repr='Placeholder')

My understanding from PEP 661 is that this is already handled by the sentinel's __module__ attribute.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should be fine, though you can always add a new test.

I made this same change in #149088, along with the corresponding change to the C implementation. I didn't push forward on it because of pushback around hypothetical code relying on type(Placeholder).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to revive Jelle's PR which also handles the C implementation.

@rhettinger rhettinger closed this Oct 31, 2026
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.

3 participants