Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
6 changes: 3 additions & 3 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1075,12 +1075,12 @@ Capsule objects
Sentinel objects
~~~~~~~~~~~~~~~~

.. class:: sentinel(name, /)
.. class:: sentinel(name, /, *, repr=None)

A type used to define sentinel values. The *name* argument should be the
name of the variable to which the return value shall be assigned.

Assigning attributes to a sentinel is deprecated.
Assigning attributes to a sentinel is deprecated (except for __module__).
Comment thread
zedzhen marked this conversation as resolved.

Example::

Expand All @@ -1106,7 +1106,7 @@ Sentinel objects
Now supports pickle and will be reduced as a singleton.
Renamed from `Sentinel` to `sentinel`, `Sentinel` is deprecated.
Automatic `repr` string no longer has angle brackets.
`repr` parameter was deprecated.
`repr` as a positional argument is deprecated.
`name` as a keyword is deprecated.
Subclassing and attribute assignment are deprecated.

Expand Down
12 changes: 8 additions & 4 deletions src/typing_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,10 @@ class sentinel:
def __init__(
self,
__name: str = _sentinel_placeholder,
__repr: typing.Optional[str] = _sentinel_placeholder,
/,
repr: typing.Optional[str] = None,
*,
repr: typing.Optional[str] = _sentinel_placeholder,
name: str = _sentinel_placeholder,
) -> None:
if name is not _sentinel_placeholder:
Expand All @@ -204,13 +205,16 @@ def __init__(
__name = name
if __name is _sentinel_placeholder:
raise TypeError("First parameter 'name' is required")
if repr is not None:
if __repr is not _sentinel_placeholder:
warnings.warn(
"The 'repr' parameter is deprecated "
"and will be removed in Python 3.15.",
"Passing 'repr' as a position argument is deprecated; "
Comment thread
zedzhen marked this conversation as resolved.
Outdated
"pass it by keyword instead.",
DeprecationWarning,
stacklevel=2,
)
repr = __repr
if repr is _sentinel_placeholder:
repr = None
Comment thread
zedzhen marked this conversation as resolved.
Outdated

self.__name__ = __name
self._repr = repr if repr is not None else __name
Expand Down
Loading