@@ -1238,6 +1238,22 @@ def _update_func_cell_for__class__(f, oldcls, newcls):
12381238 return False
12391239
12401240
1241+ _object_members_values = {
1242+ value for name , value in
1243+ (
1244+ * inspect .getmembers_static (object ),
1245+ * inspect .getmembers_static (object ())
1246+ )
1247+ }
1248+
1249+
1250+ def _is_not_object_member (v ):
1251+ try :
1252+ return v not in _object_members_values
1253+ except TypeError :
1254+ return True
1255+
1256+
12411257def _find_inner_functions (obj , seen = None , depth = 0 ):
12421258 if seen is None :
12431259 seen = set ()
@@ -1253,22 +1269,14 @@ def _find_inner_functions(obj, seen=None, depth=0):
12531269 if depth > 2 :
12541270 return None
12551271
1256- for attribute in dir (obj ):
1257- try :
1258- value = inspect .getattr_static (obj , attribute )
1259- except AttributeError :
1260- continue
1261- builtin_value = inspect .getattr_static (object , attribute , None )
1262- if value is builtin_value :
1263- # don't waste time on builtin objects
1264- continue
1265- if (
1266- # isinstance() would trigger `value.__getattribute__("__class__")`
1267- type (value ) is types .MemberDescriptorType
1268- and type not in inspect ._static_getmro (type (obj ))
1269- ):
1272+ obj_is_type_instance = type in inspect ._static_getmro (type (obj ))
1273+ for _ , value in inspect .getmembers_static (obj , _is_not_object_member ):
1274+ value_type = type (value )
1275+ if value_type is types .MemberDescriptorType and not obj_is_type_instance :
12701276 value = value .__get__ (obj )
1271- if isinstance (value , types .FunctionType ):
1277+ value_type = type (value )
1278+
1279+ if value_type is types .FunctionType :
12721280 yield inspect .unwrap (value )
12731281 else :
12741282 yield from _find_inner_functions (value , seen , depth )
0 commit comments