def check_method_has_attr_via_mro(obj, method_name, attr_name):
    """ Check that method has specified attr in MRO
    """
    for method in resolve_mro(obj, method_name, callable):
        if hasattr(method, attr_name):
            return True
    return False
Exemple #2
0
def get_method_priority_via_mro(obj, method_name, attr_name, default):
    """ Get the priority for method from attr 'attr_name',
        checking all overrides in mro order and looking for first non None
        value. If no such value found, then default value will be applied
    """
    for method in resolve_mro(obj, method_name, callable):
        meth_val = getattr(method, attr_name, None)
        if meth_val is not None:
            return meth_val
    return default
Exemple #3
0
def get_method_fields_via_mro(obj, method_name, attr_name):
    """ Get set of all fields metioned in attr 'attr_name' of method in all
        method overrides in subclasses
    """
    return set(field for method in resolve_mro(obj, method_name, callable)
               for field in getattr(method, attr_name, []))