Skip to content

Commit

Permalink
simplify PyPlaceholder implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dg-pb committed Jun 25, 2024
1 parent bc1fdbd commit 3067221
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions Lib/functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,17 @@ def reduce(function, sequence, initial=_initial_missing):
################################################################################


class PlaceholderTypeBase:
class PlaceholderType:
"""The type of the Placeholder singleton.
Used as a placeholder for partial arguments.
"""
__instance = None
__slots__ = ()

def __init_subclass__(cls, *args, **kwargs):
raise TypeError(f"type '{cls.__name__}' is not an acceptable base type")

def __new__(cls):
if cls.__instance is None:
cls.__instance = object.__new__(cls)
Expand All @@ -296,16 +299,9 @@ def __repr__(self):
def __reduce__(self):
return 'Placeholder'

def placeholder_init_subclass(cls, *args, **kwargs):
raise TypeError(f"type '{cls.__name__}' is not an acceptable base type")

Placeholder = type(
'PlaceholderType',
(PlaceholderTypeBase,),
{'__slots__': (), '__init_subclass__': placeholder_init_subclass}
)()

del PlaceholderTypeBase, placeholder_init_subclass
Placeholder = PlaceholderType()
del PlaceholderType

def _partial_prepare_new(cls, func, args, keywords):
if args:
Expand Down

0 comments on commit 3067221

Please sign in to comment.