def _safe_setattr(obj, name, value):
okey = id(obj)<EOL>if okey in _set_failures or okey in _final_objs:<EOL><INDENT>return False<EOL><DEDENT>import inspect<EOL>try:<EOL><INDENT>if inspect.ismethod(obj):<EOL><INDENT>setattr(obj.__func__, name, value)<EOL>return True<EOL><DEDENT>else:<EOL><INDENT>if isinstance(obj, dict): <EOL><INDENT>obj[name] = value<EOL><DEDENT>else:<EOL><INDENT>setattr(obj, name, value)<EOL><DEDENT>return True<EOL><DEDENT><DEDENT>except (TypeError, AttributeError):<EOL><INDENT>_set_failures.append(okey)<EOL>msg.warn("<STR_LIT>".format(name, value, obj))<EOL>return False<EOL><DEDENT>
Safely sets the attribute of the specified object. This includes not
    setting attributes for final objects and setting __func__ for instancemethod
    typed objects.

    Args:
        obj: object to set an attribute for.
        name (str): new attribute name.
        value: new attribute value.

    Returns:
        bool: True if the set attribute was successful.