Skip to content

Commit e86435c

Browse files
Apply suggestions from code review
Update related tests Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
1 parent cc08d14 commit e86435c

3 files changed

Lines changed: 13 additions & 10 deletions

File tree

doc/index.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ Sentinel objects
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-
Assigning attributes to a sentinel including `__weakref__` is forbidden.
1079+
Assigning attributes to a sentinel is deprecated.
10801080

10811081
Example::
10821082

@@ -1096,12 +1096,15 @@ Sentinel objects
10961096

10971097
.. versionchanged:: 4.16.0
10981098

1099+
The implementation of this class has been updated to conform to
1100+
the accepted version of :pep:`661`.
1101+
10991102
Now supports pickle and will be reduced as a singleton.
11001103
Renamed from `Sentinel` to `sentinel`, `Sentinel` is deprecated.
11011104
Automatic `repr` string no longer has angle brackets.
11021105
`repr` parameter was deprecated.
11031106
`name` as a keyword is deprecated.
1104-
Subclasssing and attribute assignment are deprecated.
1107+
Subclassing and attribute assignment are deprecated.
11051108

11061109

11071110
Pure aliases

src/test_typing_extensions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9551,7 +9551,7 @@ def test_sentinel_no_repr(self):
95519551
self.assertEqual(repr(sentinel_no_repr), 'sentinel_no_repr')
95529552

95539553
def test_sentinel_deprecated_explicit_repr(self):
9554-
with self.assertWarnsRegex(DeprecationWarning, r"'repr' is deprecated and must be removed"):
9554+
with self.assertWarnsRegex(DeprecationWarning, r"'repr' parameter is deprecated and will be removed"):
95559555
sentinel_explicit_repr = sentinel('sentinel_explicit_repr', repr='explicit_repr')
95569556

95579557
self.assertEqual(repr(sentinel_explicit_repr), 'explicit_repr')
@@ -9596,15 +9596,15 @@ def test_sentinel_picklable_anonymous(self):
95969596
self.assertIs(anonymous_sentinel, pickle.loads(pickle.dumps(anonymous_sentinel, protocol=proto)))
95979597

95989598
def test_sentinel_deprecated(self):
9599-
with self.assertWarnsRegex(DeprecationWarning, r"Subclassing sentinel is forbidden by PEP 661"):
9599+
with self.assertWarnsRegex(DeprecationWarning, r"Subclassing sentinel is deprecated"):
96009600
class SentinelSubclass(Sentinel):
96019601
pass
96029602
with self.assertRaisesRegex(TypeError, r"First parameter 'name' is required"):
96039603
sentinel()
96049604

9605-
with self.assertWarnsRegex(DeprecationWarning, r"'name' is positional-only and must not be a keyword parameter"):
9605+
with self.assertWarnsRegex(DeprecationWarning, r"Passing 'name' as a keyword argument is deprecated"):
96069606
my_sentinel = Sentinel(name="my_sentinel")
9607-
with self.assertWarnsRegex(DeprecationWarning, r"Setting attributes on sentinel is deprecated"):
9607+
with self.assertWarnsRegex(DeprecationWarning, r"Setting attribute 'foo' on sentinel objects is deprecated"):
96089608
my_sentinel.foo = "bar"
96099609

96109610

src/typing_extensions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def __init__(
193193
) -> None:
194194
if name is not _sentinel_placeholder:
195195
warnings.warn(
196-
"'name' is positional-only and must not be a keyword parameter",
196+
"Passing 'name' as a keyword argument is deprecated; pass it positionally instead.",
197197
DeprecationWarning,
198198
stacklevel=2,
199199
)
@@ -202,7 +202,7 @@ def __init__(
202202
raise TypeError("First parameter 'name' is required")
203203
if repr is not None:
204204
warnings.warn(
205-
"'repr' is deprecated and must be removed",
205+
"The 'repr' parameter is deprecated and will be removed in Python 3.15.",
206206
DeprecationWarning,
207207
stacklevel=2,
208208
)
@@ -215,7 +215,7 @@ def __init__(
215215

216216
def __init_subclass__(cls):
217217
warnings.warn(
218-
"Subclassing sentinel is forbidden by PEP 661",
218+
"Subclassing sentinel is deprecated and will be disallowed in Python 3.15",
219219
DeprecationWarning,
220220
stacklevel=2,
221221
)
@@ -224,7 +224,7 @@ def __init_subclass__(cls):
224224
def __setattr__(self, attr: str, value: object) -> None:
225225
if attr not in {"__name__", "_repr", "__module__"}:
226226
warnings.warn(
227-
"Setting attributes on sentinel is deprecated",
227+
f"Setting attribute {attr!r} on sentinel objects is deprecated and will be disallowed in Python 3.15.",
228228
DeprecationWarning,
229229
stacklevel=2,
230230
)

0 commit comments

Comments
 (0)