@@ -55,19 +55,25 @@ def decorator(function):
5555 if not monkeypatchee_is_a_class :
5656 raise NotImplemented ("I don't know how to monkeypatch a "
5757 "descriptor onto a non-class object." )
58- ### Getting name of descriptor: ###################################
59- # #
60- if isinstance (function , caching .CachedProperty ):
61- if not isinstance (function .getter , types .FunctionType ):
62- raise NotImplemented
63- name_ = function .getter .__name__
64- elif isinstance (function , (classmethod , staticmethod )):
65- name_ = function .__func__ .__name__
66- else :
67- raise NotImplemented ("`monkeypatch_method` doesn't know how "
68- "to handle this kind of function." )
69- # #
70- ### Finished getting name of descriptor. ##########################
58+ if not name :
59+ ### Getting name of descriptor: ###############################
60+ # #
61+ if isinstance (function , caching .CachedProperty ):
62+ if not isinstance (function .getter , types .FunctionType ):
63+ raise NotImplemented
64+ name_ = function .getter .__name__
65+ elif isinstance (function , (classmethod , staticmethod )):
66+ name_ = function .__func__ .__name__
67+ elif isinstance (function , property ):
68+ name_ = function .fget .__name__
69+ else :
70+ raise NotImplemented (
71+ "`monkeypatch_method` doesn't know how to get the "
72+ "name of this kind of function automatically, try "
73+ "manually."
74+ )
75+ # #
76+ ### Finished getting name of descriptor. ######################
7177 setattr (monkeypatchee , name_ , function )
7278 return function
7379
0 commit comments