def mro_lookup(cls, attr, stop=set(), monkey_patched=[]):
 for node in cls.mro():
  if (node in stop):
   try:
    value = node.__dict__[attr]
    module_origin = value.__module__
   except (AttributeError, KeyError):
    pass
   else:
    if (module_origin not in monkey_patched):
     return node
   return
  if (attr in node.__dict__):
   return node

def mro_lookup ( cls , attr , stop = set ( ) , monkey_patched = [ ] ) : for node in cls . mro ( ) : if ( node in stop ) : try : value = node . __dict__ [ attr ] module_origin = value . __module__ except ( AttributeError , KeyError ) : pass else : if ( module_origin not in monkey_patched ) : return node return if ( attr in node . __dict__ ) : return node
return the first node by mro order that defines an attribute .