Skip to content

gh-149083: Make functools.Placeholder a sentinel#149088

Open
JelleZijlstra wants to merge 1 commit intopython:mainfrom
JelleZijlstra:placehold
Open

gh-149083: Make functools.Placeholder a sentinel#149088
JelleZijlstra wants to merge 1 commit intopython:mainfrom
JelleZijlstra:placehold

Conversation

@JelleZijlstra
Copy link
Copy Markdown
Member

@JelleZijlstra JelleZijlstra commented Apr 28, 2026

This greatly simplifies the code. The only behavioral difference observable in the tests is that type(Placeholder)() no longer works, because Placeholder is now an instance of sentinel.


📚 Documentation preview 📚: https://cpython-previews--149088.org.readthedocs.build/

@picnixz
Copy link
Copy Markdown
Member

picnixz commented Apr 28, 2026

Is type(Placeholder)() acceptable? I would have actually expected that type(MySentinel)() returned the sentinel as for type(None)() but it's not the case since MySentinel is an instance of a sentinel!

@picnixz
Copy link
Copy Markdown
Member

picnixz commented Apr 28, 2026

Actually, since we're launching beta, it may be ok to change this and see if it breaks something

@JelleZijlstra
Copy link
Copy Markdown
Member Author

It's difficult to imagine why people would be doing things like type(Placeholder)() outside of test code, but you never know.

@picnixz
Copy link
Copy Markdown
Member

picnixz commented Apr 28, 2026

I can see people doing type(Placeholder) for maybe their mypy plugin or whatever, or even for checking if a default is a placeholder instance and do something else with it (though they should assume that it's a singleton so there is no real need to check placeholders through isinstance checks). I think there was a discussion when introducing placeholders about type(P)() returning P but I can't find it (and maybe I remembered wrongly). One could argue that type(Placeholder) could also be used for type annotations =/

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.

2 participants