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