Skip to content

Commit eef74f3

Browse files
committed
more
1 parent 44bb41b commit eef74f3

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

peps/pep-0661.rst

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,17 @@ A new built-in callable named ``sentinel`` will be added.
146146
>>> MISSING
147147
MISSING
148148

149+
``sentinel()`` takes a single positional-only argument, ``name``, which must
150+
be a ``str``. Passing a non-string raises ``TypeError``. The name is used as
151+
the sentinel's name and repr.
152+
153+
Sentinel objects have two public attributes:
154+
155+
* ``__name__`` is the sentinel's name.
156+
* ``__module__`` is the name of the module where ``sentinel()`` was called.
157+
158+
``sentinel`` may not be subclassed.
159+
149160
Each call to ``sentinel(name)`` returns a new sentinel object. If a sentinel
150161
is needed in more than one place, it should be assigned to a variable and that
151162
same object should be reused explicitly, just as with the common
@@ -269,10 +280,15 @@ behavior follows::
269280
class sentinel:
270281
"""Unique sentinel values."""
271282

272-
__slots__ = ("_name", "_module_name")
283+
__slots__ = ("__name__", "_module_name")
284+
285+
def __init_subclass__(cls):
286+
raise TypeError("type 'sentinel' is not an acceptable base type")
273287

274288
def __init__(self, name, /):
275-
self._name = str(name)
289+
if not isinstance(name, str):
290+
raise TypeError("sentinel name must be a string")
291+
self.__name__ = name
276292
self._module_name = sys._getframemodulename(1)
277293
if self._module_name is None:
278294
self._module_name = __name__
@@ -282,10 +298,10 @@ behavior follows::
282298
return self._module_name
283299

284300
def __repr__(self):
285-
return self._name
301+
return self.__name__
286302

287303
def __reduce__(self):
288-
return self._name
304+
return self.__name__
289305

290306
def __copy__(self):
291307
return self

0 commit comments

Comments
 (0)