Skip to content

Commit 44a50ed

Browse files
committed
review edits
1 parent d65f194 commit 44a50ed

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

Lib/functools.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,11 @@ def __setstate__(self, state):
430430
except ImportError:
431431
pass
432432

433-
_NULL = object()
434433
_UNKNOWN_DESCRIPTOR = object()
435434
_STD_METHOD_TYPES = (staticmethod, classmethod, FunctionType, partial)
436435
_ONE_PLACEHOLDER_TUPLE = (Placeholder,)
436+
_VOID_LAMBDA = lambda *_, **__: None
437+
437438

438439
# Descriptor version
439440
class partialmethod:
@@ -452,7 +453,7 @@ class partialmethod:
452453
def __init__(self, func, /, *args, **keywords):
453454
if isinstance(func, partialmethod):
454455
# Subclass optimization
455-
temp = partial(lambda: None, *func.args, **func.keywords)
456+
temp = partial(_VOID_LAMBDA, *func.args, **func.keywords)
456457
temp = partial(temp, *args, **keywords)
457458
func = func.func
458459
args = temp.args
@@ -473,12 +474,6 @@ def __init__(self, func, /, *args, **keywords):
473474
# Unknown descriptor
474475
self.method = _UNKNOWN_DESCRIPTOR
475476

476-
def _set_func_attrs(self, func):
477-
func.__partialmethod__ = self
478-
if self.__isabstractmethod__:
479-
func = abstractmethod(func)
480-
return func
481-
482477
def _make_method(self):
483478
args = self.args
484479
func = self.func
@@ -515,9 +510,12 @@ def __get__(self, obj, cls=None):
515510
result.__partialmethod__ = self
516511
if self.__isabstractmethod__:
517512
result = abstractmethod(result)
518-
__self__ = getattr(new_func, '__self__', _NULL)
519-
if __self__ is not _NULL:
520-
result.__self__ = __self__
513+
try:
514+
obj = new_func.__self__
515+
except AttributeError:
516+
pass
517+
else:
518+
result.__self__ = obj
521519
return result
522520
if method is None:
523521
# Cache method
@@ -530,6 +528,7 @@ def __isabstractmethod__(self):
530528

531529
__class_getitem__ = classmethod(GenericAlias)
532530

531+
533532
# Helper functions
534533

535534
def _unwrap_partial(func):

0 commit comments

Comments
 (0)