Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/_collections_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Lib/_pydatetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 2 additions & 7 deletions Lib/configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -386,13 +381,13 @@ def __init__(self, msg=''):
Error.__init__(self, msg)


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


# 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:
Expand Down
5 changes: 1 addition & 4 deletions Lib/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,7 @@ class FrozenInstanceError(AttributeError): pass
# A sentinel object for default values to signal that a default
# factory will be used. This is given a nice repr() which will appear
# in the function signature of dataclasses' constructors.
class _HAS_DEFAULT_FACTORY_CLASS:
def __repr__(self):
return '<factory>'
_HAS_DEFAULT_FACTORY = _HAS_DEFAULT_FACTORY_CLASS()
_HAS_DEFAULT_FACTORY = sentinel('<factory>')

# A sentinel object to detect if a parameter is supplied or not. Use
# a class to give it a better repr.
Expand Down
2 changes: 1 addition & 1 deletion Lib/functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,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):
Expand Down
2 changes: 1 addition & 1 deletion Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -1691,7 +1691,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__

Expand Down
2 changes: 1 addition & 1 deletion Lib/sched.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
6 changes: 1 addition & 5 deletions Lib/traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@ def extract_tb(tb, limit=None):
"another exception occurred:\n\n")


class _Sentinel:
def __repr__(self):
return "<implicit>"

_sentinel = _Sentinel()
_sentinel = sentinel("<implicit>")

def _parse_value_tb(exc, value, tb):
if (value is _sentinel) != (tb is _sentinel):
Expand Down
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`.
Loading