Skip to content

Commit 0f23901

Browse files
committed
Deprecate sentinel repr parameter
`repr` is not in PEP 661
1 parent f68007e commit 0f23901

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
@@ -391,16 +391,14 @@ class sentinel:
391391
"""Create a unique sentinel object.
392392
393393
*name* should be the name of the variable to which the return value shall be assigned.
394-
395-
*repr*, if supplied, will be used for the repr of the sentinel object.
396-
If not provided, "<name>" will be used.
397394
"""
398395

399396
@overload
400-
def __init__(self, name: str, /, *, repr: typing.Optional[str] = None): ...
397+
def __init__(self, name: str, /): ...
401398

402399
@overload
403-
@deprecated("'name' must be positional-only, 'repr' must be keyword-only.")
400+
@deprecated("'name' must be positional-only, \
401+
'repr' is deprecated and must be removed.")
404402
def __init__(self, name: str, repr: typing.Optional[str] = None): ...
405403

406404
def __init__(

0 commit comments

Comments
 (0)