Skip to content

Commit b03a69e

Browse files
committed
Simplify Placeholder with the new sentinel() class
1 parent 5a97efe commit b03a69e

2 files changed

Lines changed: 1 addition & 30 deletions

File tree

‎Lib/functools.py‎

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -275,29 +275,7 @@ def reduce(function, sequence, /, initial=_initial_missing):
275275
################################################################################
276276

277277

278-
class _PlaceholderType:
279-
"""The type of the Placeholder singleton.
280-
281-
Used as a placeholder for partial arguments.
282-
"""
283-
__instance = None
284-
__slots__ = ()
285-
286-
def __init_subclass__(cls, *args, **kwargs):
287-
raise TypeError(f"type '{cls.__name__}' is not an acceptable base type")
288-
289-
def __new__(cls):
290-
if cls.__instance is None:
291-
cls.__instance = object.__new__(cls)
292-
return cls.__instance
293-
294-
def __repr__(self):
295-
return 'Placeholder'
296-
297-
def __reduce__(self):
298-
return 'Placeholder'
299-
300-
Placeholder = _PlaceholderType()
278+
Placeholder = sentinel('Placeholder') # _PlaceholderType()
301279

302280
def _partial_prepare_merger(args):
303281
if not args:

‎Lib/test/test_functools.py‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,6 @@ def test_placeholders_kw_restriction(self):
279279
self.assertEqual(len(actual_kwds), 1)
280280
self.assertIs(actual_kwds['a'], ALWAYS_EQ)
281281

282-
def test_construct_placeholder_singleton(self):
283-
PH = self.module.Placeholder
284-
tp = type(PH)
285-
self.assertIs(tp(), PH)
286-
self.assertRaises(TypeError, tp, 1, 2)
287-
self.assertRaises(TypeError, tp, a=1, b=2)
288-
289282
def test_repr(self):
290283
args = (object(), object())
291284
args_repr = ', '.join(repr(a) for a in args)

0 commit comments

Comments
 (0)