Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd217592

Browse files
committed
small edits
1 parentf323dbd commitd217592

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

‎Lib/functools.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -451,10 +451,6 @@ class partialmethod:
451451
__repr__=_partial_repr
452452

453453
def__init__(self,func,/,*args,**keywords):
454-
ifnotcallable(func)andgetattr(func,'__get__',None)isNone:
455-
raiseTypeError(f'the first argument{func!r} must be a callable '
456-
'or a descriptor')
457-
458454
ifisinstance(func,partialmethod):
459455
# Subclass optimization
460456
temp=partial(lambda:None,*func.args,**func.keywords)
@@ -467,8 +463,12 @@ def __init__(self, func, /, *args, **keywords):
467463
self.args=args
468464
self.keywords=keywords
469465

470-
if (isinstance(func,_STD_METHOD_TYPES)or
471-
getattr(func,'__get__',None)isNone):
466+
ifisinstance(func,_STD_METHOD_TYPES):
467+
self.method=None
468+
elifgetattr(func,'__get__',None)isNone:
469+
ifnotcallable(func):
470+
raiseTypeError(f'the first argument{func!r} must be a callable '
471+
'or a descriptor')
472472
self.method=None
473473
else:
474474
# Unknown descriptor
@@ -486,22 +486,26 @@ def _make_method(self):
486486

487487
# 4 cases
488488
ifisinstance(func,staticmethod):
489-
func=partial(func.__wrapped__,*args,**self.keywords)
490-
self._set_func_attrs(func)
491-
returnstaticmethod(func)
489+
deco=staticmethod
490+
method=partial(func.__wrapped__,*args,**self.keywords)
492491
elifisinstance(func,classmethod):
492+
deco=classmethod
493493
ph_args= (Placeholder,)ifargselse ()
494-
func=partial(func.__wrapped__,*ph_args,*args,**self.keywords)
495-
self._set_func_attrs(func)
496-
returnclassmethod(func)
494+
method=partial(func.__wrapped__,*ph_args,*args,**self.keywords)
497495
else:
498496
# instance method. 2 cases:
499497
# a) FunctionType | partial
500498
# b) callable object without __get__
499+
deco=None
501500
ph_args= (Placeholder,)ifargselse ()
502-
func=partial(func,*ph_args,*args,**self.keywords)
503-
self._set_func_attrs(func)
504-
returnfunc
501+
method=partial(func,*ph_args,*args,**self.keywords)
502+
503+
method.__partialmethod__=self
504+
ifself.__isabstractmethod__:
505+
method=abstractmethod(method)
506+
ifdecoisnotNone:
507+
method=deco(method)
508+
returnmethod
505509

506510
def__get__(self,obj,cls=None):
507511
method=self.method
@@ -510,7 +514,9 @@ def __get__(self, obj, cls=None):
510514
# Need to get callable at runtime and apply partial on top
511515
new_func=self.func.__get__(obj,cls)
512516
result=partial(new_func,*self.args,**self.keywords)
513-
self._set_func_attrs(func)
517+
result.__partialmethod__=self
518+
ifself.__isabstractmethod__:
519+
result=abstractmethod(result)
514520
__self__=getattr(new_func,'__self__',_NULL)
515521
if__self__isnot_NULL:
516522
result.__self__=__self__

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp