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

gh-148829: Add PySentinel_CheckExact() by scoder · Pull Request #149725 · python/cpython · GitHub

Repository navigation

gh-148829: Add PySentinel_CheckExact() - #149725

Merged
vstinner merged 5 commits into
python:mainfrom
scoder:pysentinel_checkexact
May 13, 2026
Merged

vstinner merged 5 commits into
python:mainfrom
scoder:pysentinel_checkexact

Conversation

scoder commented May 12, 2026 •
edited
Loading

Copy link
Copy Markdown
Contributor

As suggested in https://discuss.python.org/t/pep-661-sentinel-values/9126/343, this PR adds a PySentinel_CheckExact() C macro and makes PySentinel_Check() an alias, which can change if/when we allow subtypes in the future.

The discussion seems to suggest that subtyping will be valuable at some point. Adding both C macros now allows to write concise code on user side that (hopefully) requires less changes later.

I chose to make PySentinel_Check() an alias of PySentinel_CheckExact() and not the other way round because the current C macro actually does an exact check, so its correct name is PySentinel_CheckExact().

read-the-docs-community Bot commented May 12, 2026 •
edited
Loading

Copy link
Copy Markdown

scoder commented May 12, 2026

Copy link
Copy Markdown
Contributor Author

I set the skipNews tag since we're still pre-release, but OTOH, we're post-beta1, so we might still want to add a news entry. Should I add one?

I was also mildly surprised to find the tests in object.c. By name, that seems quite generic for tests that belong to a specific builtin type.

scoder commented May 12, 2026

Copy link
Copy Markdown
Contributor Author

@vstinner @JelleZijlstra

Copy link
Copy Markdown
Member

Ah, sorry I forgot to follow up on this. I'm OK with the change and we should be able to do it in the beta phase, but we will need a NEWS entry since we already made a (beta) release with the old logic.

scoder removed the skip news label May 12, 2026
Comment thread Doc/c-api/sentinel.rst Outdated
Comment thread Doc/c-api/sentinel.rst Outdated
Comment thread Doc/c-api/sentinel.rst Outdated

vstinner 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

LGTM

Comment thread Doc/c-api/sentinel.rst
Return true if *o* is a :class:`sentinel` object or a subtype.
The :class:`sentinel` type does not currently allow subclasses,
so this check is exact.
Future Python versions may choose to allow subtyping.

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

Can you add "This function always succeeds." to both functions?

vstinner enabled auto-merge (squash) May 13, 2026 09:44
vstinner merged commit 94df625 into python:main May 13, 2026
55 checks passed

Copy link
Copy Markdown

Thanks @scoder for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

bedevere-app Bot commented May 13, 2026

Copy link
Copy Markdown

GH-149766 is a backport of this pull request to the 3.15 branch.

bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label May 13, 2026

Copy link
Copy Markdown
Member

Merged. Thanks @scoder for your contribution!

vstinner pushed a commit that referenced this pull request May 13, 2026
gh-148829: Add PySentinel_CheckExact() (GH-149725)
(cherry picked from commit 94df625)

Co-authored-by: scoder <stefan_ml@behnel.de>
scoder deleted the pysentinel_checkexact branch May 13, 2026 12:16
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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL