FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-149083: Convert some private and simple sentinels to PEP 661 by JelleZijlstra · Pull Request #149084 · python/cpython · GitHub

/ cpython Public

gh-149083: Convert some private and simple sentinels to PEP 661 - #149084

Open
JelleZijlstra wants to merge 9 commits into
python:mainfrom
JelleZijlstra:more-sentinels
Open

gh-149083: Convert some private and simple sentinels to PEP 661#149084
JelleZijlstra wants to merge 9 commits into
python:mainfrom
JelleZijlstra:more-sentinels

Conversation

JelleZijlstra commented Apr 28, 2026
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

picnixz left a comment

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

There is a sentinel in hashlib.py to detect usage of arguments and raise appropriate warnings/errors so could you also update it? it's a hacky code because I needed to mirror the C behavior in some sense.

picnixz left a comment

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

In dataclasses, there is also _FIELD, _FIELD_CLASSVAR and _FIELD_INITVAR that you could update I think?

Copy link
Copy Markdown
Member Author

I was going to leave those dataclasses objects alone since they're instances of a common class, and I wouldn't be able to preserve that behavior.

Copy link
Copy Markdown
Contributor

base64._NOT_SPECIFIED is also a candidate (I don't know why, but it's currently a list of one string)

Comment thread Lib/configparser.py Outdated

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #32562194 | 📁 Comparing 0ebd184 against main (70e365c)

  🔍 Preview build  

71 files changed · ± 70 modified · - 1 deleted

± Modified

- Deleted

JelleZijlstra added the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label May 9, 2026

serhiy-storchaka left a comment
edited
Loading

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think that using names like "<not specified>", "<omitted>", etc for sentinels shown in function signatures will more clearly show that the behavior when the argument is not specified differs from the behavior when the argument is specified with any value.

Currently, for functions implemented in Argument Clinic it is shown as <unrepresentable>, but <not specified> would be better in most cases.

serhiy-storchaka left a comment

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

No need to use sentinel() for sentinels not visible to users.

Comment thread Lib/_collections_abc.py
raise KeyError

__marker = object()
__marker = sentinel("__marker", repr="<marker>")

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Would not it be better to stick to some standard representation like <not specified> for sentinels only exposed in function signatures?

pop(self, key, default=<not specified>)

And why do we need a name for private sentinels? They are not supposed to be pickleable.

Comment thread Lib/configparser.py


UNNAMED_SECTION = _UnnamedSection()
UNNAMED_SECTION = sentinel("UNNAMED_SECTION", repr="<UNNAMED_SECTION>")

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

UNNAMED_SECTION is in the public API, it should not have obscure repr.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

What would you prefer?

Comment thread Lib/functools.py
################################################################################

_NOT_FOUND = object()
_NOT_FOUND = sentinel("_NOT_FOUND", repr="<not found>")

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It is not visible to user. It can remain object().

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think it's still cleaner to use sentinel. Also, users inspecting the cache for debugging purposes can see this object.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting merge needs backport to 3.15 pre-release feature fixes, bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants


Back | FazBrowse Home | New Git URL