4040
4141from .annotations import apply_annotations
4242from .constants import INTERNALS_DICT , NOTHING , REPLACE_NAME
43- from .functions import get_fields , get_flags
43+ from .functions import get_fields , get_flags , get_methods
4444
4545try :
4646 from ._cached_methods import init_cache , setattr_cache
@@ -109,6 +109,15 @@ def generate(self):
109109 return method
110110
111111
112+ def _get_method (cls , name ):
113+ try :
114+ methods = get_methods (cls )
115+ except TypeError :
116+ return None
117+
118+ return methods .get (name , None )
119+
120+
112121class MethodMaker :
113122 """
114123 The descriptor class to place where methods should be generated.
@@ -135,16 +144,18 @@ def __repr__(self):
135144 return f"<MethodMaker for { self .funcname !r} method>"
136145
137146 def __get__ (self , inst , cls ):
138- # This can be called via super().funcname(...) in which case the class
147+ # This can be called via a subclass or through
148+ # super().funcname(...) in which case the class
139149 # may not be the correct one. If this is the correct class
140150 # it should have this descriptor in the class dict under
141151 # the correct funcname.
142152 # Otherwise is should be found in the MRO of the class.
143- if cls .__dict__ .get (self .funcname ) is self :
153+
154+ if _get_method (cls , self .funcname ) is self :
144155 gen_cls = cls
145156 else :
146157 for c in cls .__mro__ [1 :]: # skip 'cls' as special cased
147- if c . __dict__ . get ( self .funcname ) is self :
158+ if _get_method ( c , self .funcname ) is self :
148159 gen_cls = c
149160 break
150161 else :
0 commit comments