Skip to content

Commit ab1c49d

Browse files
committed
Deprecate sentinel repr parameter
`repr` is not in PEP 661
1 parent 6f26100 commit ab1c49d

3 files changed

Lines changed: 7 additions & 10 deletions

File tree

doc/index.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,17 +1071,16 @@ Capsule objects
10711071
Sentinel objects
10721072
~~~~~~~~~~~~~~~~
10731073

1074-
.. class:: sentinel(name, /, *, repr=None)
1074+
.. class:: sentinel(name, /)
10751075

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

1079-
If *repr* is provided, it will be used for the :meth:`~object.__repr__`
1080-
of the sentinel object. If not provided, ``"<name>"`` will be used.
1081-
10821079
A sentinel is bound to the module it is created within,
10831080
sentinels are not equal to similar named sentinels from other modules.
10841081

1082+
Assigning attributes to a sentinel including `__weakref__` is forbidden.
1083+
10851084
Example::
10861085

10871086
>>> from typing_extensions import sentinel, assert_type

src/test_typing_extensions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9550,7 +9550,7 @@ def test_sentinel_no_repr(self):
95509550
self.assertEqual(sentinel_no_repr.__name__, 'sentinel_no_repr')
95519551
self.assertEqual(repr(sentinel_no_repr), 'sentinel_no_repr')
95529552

9553-
def test_sentinel_explicit_repr(self):
9553+
def test_sentinel_deprecated_explicit_repr(self):
95549554
sentinel_explicit_repr = sentinel('sentinel_explicit_repr', repr='explicit_repr')
95559555

95569556
self.assertEqual(repr(sentinel_explicit_repr), 'explicit_repr')

src/typing_extensions.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,14 @@ class sentinel:
177177
"""Create a unique sentinel object.
178178
179179
*name* should be the name of the variable to which the return value shall be assigned.
180-
181-
*repr*, if supplied, will be used for the repr of the sentinel object.
182-
If not provided, "<name>" will be used.
183180
"""
184181

185182
@overload
186-
def __init__(self, name: str, /, *, repr: typing.Optional[str] = None): ...
183+
def __init__(self, name: str, /): ...
187184

188185
@overload
189-
@deprecated("'name' must be positional-only, 'repr' must be keyword-only.")
186+
@deprecated("'name' must be positional-only, \
187+
'repr' is deprecated and must be removed.")
190188
def __init__(self, name: str, repr: typing.Optional[str] = None): ...
191189

192190
def __init__(

0 commit comments

Comments
 (0)