File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -933,6 +933,7 @@ def __init__(self, func):
933
933
934
934
self .dispatcher = singledispatch (func )
935
935
self .func = func
936
+ self .attrname = None
936
937
937
938
def register (self , cls , method = None ):
938
939
"""generic_method.register(cls, func) -> func
@@ -949,12 +950,19 @@ def _method(*args, **kwargs):
949
950
_method .__isabstractmethod__ = self .__isabstractmethod__
950
951
_method .register = self .register
951
952
update_wrapper (_method , self .func )
953
+ if obj is not None :
954
+ # we set the method directly to the instance
955
+ obj .__dict__ [self .attrname ] = _method
952
956
return _method
953
957
954
958
@property
955
959
def __isabstractmethod__ (self ):
956
960
return getattr (self .func , '__isabstractmethod__' , False )
957
961
962
+ def __set_name__ (self , owner , name ):
963
+ if self .attrname is None :
964
+ self .attrname = name
965
+
958
966
959
967
################################################################################
960
968
### cached_property() - computed once per instance, cached as attribute
You can’t perform that action at this time.
0 commit comments