diff --git a/Lib/_collections_abc.py b/Lib/_collections_abc.py index 23cc6d8faae2da..7717e67a513649 100644 --- a/Lib/_collections_abc.py +++ b/Lib/_collections_abc.py @@ -925,7 +925,7 @@ def __setitem__(self, key, value): def __delitem__(self, key): raise KeyError - __marker = object() + __marker = sentinel("__marker") def pop(self, key, default=__marker): '''D.pop(k[,d]) -> v, remove specified key and return the corresponding value. diff --git a/Lib/_pydatetime.py b/Lib/_pydatetime.py index b6d68f2372850a..d388ca46013606 100644 --- a/Lib/_pydatetime.py +++ b/Lib/_pydatetime.py @@ -2447,7 +2447,7 @@ class timezone(tzinfo): __slots__ = '_offset', '_name' # Sentinel value to disallow None - _Omitted = object() + _Omitted = sentinel("_Omitted") def __new__(cls, offset, name=_Omitted): if not isinstance(offset, timedelta): raise TypeError("offset must be a timedelta") diff --git a/Lib/configparser.py b/Lib/configparser.py index a53ac87276445a..af2d872f487e0f 100644 --- a/Lib/configparser.py +++ b/Lib/configparser.py @@ -392,7 +392,7 @@ def __init__(self, msg=''): # 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") class Interpolation: diff --git a/Lib/functools.py b/Lib/functools.py index 409b2c50478c40..5a65addce24127 100644 --- a/Lib/functools.py +++ b/Lib/functools.py @@ -1137,7 +1137,7 @@ def register(self): ### cached_property() - property result cached as instance attribute ################################################################################ -_NOT_FOUND = object() +_NOT_FOUND = sentinel("_NOT_FOUND") class cached_property: def __init__(self, func): diff --git a/Lib/inspect.py b/Lib/inspect.py index a96b3dc954ef0c..22fb2ebfb074fb 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -1694,7 +1694,7 @@ def trace(context=1): # ------------------------------------------------ static version of getattr -_sentinel = object() +_sentinel = sentinel("_sentinel") _static_getmro = type.__dict__['__mro__'].__get__ _get_dunder_dict_of_class = type.__dict__["__dict__"].__get__ diff --git a/Lib/sched.py b/Lib/sched.py index fb20639d459967..56555d025f7201 100644 --- a/Lib/sched.py +++ b/Lib/sched.py @@ -46,7 +46,7 @@ Event.kwargs.__doc__ = ('''kwargs is a dictionary holding the keyword arguments for the action.''') -_sentinel = object() +_sentinel = sentinel("_sentinel") class scheduler: diff --git a/Misc/NEWS.d/next/Library/2026-04-27-19-47-24.gh-issue-149083.xa_4JR.rst b/Misc/NEWS.d/next/Library/2026-04-27-19-47-24.gh-issue-149083.xa_4JR.rst new file mode 100644 index 00000000000000..8d5d2aa4abfbc9 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-04-27-19-47-24.gh-issue-149083.xa_4JR.rst @@ -0,0 +1,2 @@ +Various private sentinels in the standard library are now instances of +:class:`sentinel`.