-
-
Notifications
You must be signed in to change notification settings - Fork 34.7k
gh-149083: Convert some private and simple sentinels to PEP 661 #149084
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1af6a3c
0ebd184
8c10d70
e6d7e28
5d6df25
35b6083
452ead4
8903a3f
5b4f551
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -372,11 +372,6 @@ def __init__(self): | |
| Error.__init__(self, "Support for UNNAMED_SECTION is disabled.") | ||
|
|
||
|
|
||
| class _UnnamedSection: | ||
|
|
||
| def __repr__(self): | ||
| return "<UNNAMED_SECTION>" | ||
|
|
||
| class InvalidWriteError(Error): | ||
| """Raised when attempting to write data that the parser would read back differently. | ||
| ex: writing a key which begins with the section header pattern would read back as a | ||
|
|
@@ -386,13 +381,13 @@ def __init__(self, msg=''): | |
| Error.__init__(self, msg) | ||
|
|
||
|
|
||
| UNNAMED_SECTION = _UnnamedSection() | ||
| UNNAMED_SECTION = sentinel("UNNAMED_SECTION", repr="<UNNAMED_SECTION>") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What would you prefer? |
||
|
|
||
|
|
||
| # Used in parser getters to indicate the default behaviour when a specific | ||
| # option is not found it to raise an exception. Created to enable `None` as | ||
| # a valid fallback value. | ||
| _UNSET = object() | ||
| _UNSET = sentinel("_UNSET", repr="<UNSET>") | ||
|
|
||
|
|
||
| class Interpolation: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1137,7 +1137,7 @@ def register(self): | |
| ### cached_property() - property result cached as instance attribute | ||
| ################################################################################ | ||
|
|
||
| _NOT_FOUND = object() | ||
| _NOT_FOUND = sentinel("_NOT_FOUND", repr="<not found>") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not visible to user. It can remain
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's still cleaner to use sentinel. Also, users inspecting the cache for debugging purposes can see this object. |
||
|
|
||
| class cached_property: | ||
| def __init__(self, func): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Various private sentinels in the standard library are now instances of | ||
| :class:`sentinel`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would not it be better to stick to some standard representation like
<not specified>for sentinels only exposed in function signatures?And why do we need a name for private sentinels? They are not supposed to be pickleable.