# Buggy code
def leave_classdef(self, cnode):
    """close a class node:
    check that instance attributes are defined in __init__ and check
    access to existent members
    """
    # check access to existent members on non metaclass classes
    ignore_mixins = get_global_option(self, "ignore-mixin-members", default=True)
    if ignore_mixins and cnode.name[-5:].lower() == "mixin":
        # We are in a mixin class. No need to try to figure out if
        # something is missing, since it is most likely that it will
        # miss.
        return

    accessed = self._accessed.pop()
    if cnode.type != "metaclass":
        self._check_accessed_members(cnode, accessed)
    # checks attributes are defined in an allowed method such as __init__
    if not self.linter.is_message_enabled("attribute-defined-outside-init"):
        return
    defining_methods = self.config.defining_attr_methods
    current_module = cnode.root()
    for attr, nodes in six.iteritems(cnode.instance_attrs):
        # skip nodes which are not in the current module and it may screw up
        # the output, while it's not worth it
        nodes = [
            n
            for n in nodes
            if not isinstance(n.statement(), (astroid.Delete, astroid.AugAssign))
            and n.root() is current_module
        ]
        if not nodes:
            continue  # error detected by typechecking
        # check if any method attr is defined in is a defining method
        if any(node.frame().name in defining_methods for node in nodes):
            continue

        # check attribute is defined in a parent's __init__
        for parent in cnode.instance_attr_ancestors(attr):
            attr_defined = False
            # check if any parent method attr is defined in is a defining method
            for node in parent.instance_attrs[attr]:
                if node.frame().name in defining_methods:
                    attr_defined = True
            if attr_defined:
                # we're done :)
                break
        else:
            # check attribute is defined as a class attribute
            try:
                cnode.local_attr(attr)
            except astroid.NotFoundError:
                for node in nodes:
                    if node.frame().name not in defining_methods:
                        # If the attribute was set by a callfunc in any
                        # of the defining methods, then don't emit
                        # the warning.
                        if _called_in_methods(node.frame(), cnode, defining_methods):
                            continue
                        self.add_message(
                            "attribute-defined-outside-init", args=attr, node=node
                        )


# Traceback (IndexError)
No config file found, using default configuration
************* Module pylint_bug
C:  1, 0: Missing module docstring (missing-docstring)
C:  1, 0: Missing class docstring (missing-docstring)
C:  2,10: Missing method docstring (missing-docstring)
R:  1, 0: Too few public methods (1/2) (too-few-public-methods)
C:  6, 0: Missing function docstring (missing-docstring)
Traceback (most recent call last):
File "/tmp/test_pylint/bin/pylint", line 11, in <module>
sys.exit(run_pylint())
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/__init__.py", line 13, in run_pylint
Run(sys.argv[1:])
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/lint.py", line 1310, in __init__
linter.check(args)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/lint.py", line 732, in check
self._do_check(files_or_modules)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/lint.py", line 863, in _do_check
self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/lint.py", line 944, in check_astroid_module
walker.walk(ast_node)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/utils.py", line 944, in walk
self.walk(child)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/utils.py", line 944, in walk
self.walk(child)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/utils.py", line 944, in walk
self.walk(child)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/utils.py", line 941, in walk
cb(astroid)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/checkers/classes.py", line 578, in visit_attribute
self._accessed[-1][attrname].append(node)
IndexError: list index out of range

# Fixed code
def leave_classdef(self, cnode):
    """close a class node:
    check that instance attributes are defined in __init__ and check
    access to existent members
    """
    # check access to existent members on non metaclass classes
    ignore_mixins = get_global_option(self, "ignore-mixin-members", default=True)
    if ignore_mixins and cnode.name[-5:].lower() == "mixin":
        # We are in a mixin class. No need to try to figure out if
        # something is missing, since it is most likely that it will
        # miss.
        return

    accessed = self._accessed.accessed(cnode)
    if cnode.type != "metaclass":
        self._check_accessed_members(cnode, accessed)
    # checks attributes are defined in an allowed method such as __init__
    if not self.linter.is_message_enabled("attribute-defined-outside-init"):
        return
    defining_methods = self.config.defining_attr_methods
    current_module = cnode.root()
    for attr, nodes in six.iteritems(cnode.instance_attrs):
        # skip nodes which are not in the current module and it may screw up
        # the output, while it's not worth it
        nodes = [
            n
            for n in nodes
            if not isinstance(n.statement(), (astroid.Delete, astroid.AugAssign))
            and n.root() is current_module
        ]
        if not nodes:
            continue  # error detected by typechecking
        # check if any method attr is defined in is a defining method
        if any(node.frame().name in defining_methods for node in nodes):
            continue

        # check attribute is defined in a parent's __init__
        for parent in cnode.instance_attr_ancestors(attr):
            attr_defined = False
            # check if any parent method attr is defined in is a defining method
            for node in parent.instance_attrs[attr]:
                if node.frame().name in defining_methods:
                    attr_defined = True
            if attr_defined:
                # we're done :)
                break
        else:
            # check attribute is defined as a class attribute
            try:
                cnode.local_attr(attr)
            except astroid.NotFoundError:
                for node in nodes:
                    if node.frame().name not in defining_methods:
                        # If the attribute was set by a callfunc in any
                        # of the defining methods, then don't emit
                        # the warning.
                        if _called_in_methods(node.frame(), cnode, defining_methods):
                            continue
                        self.add_message(
                            "attribute-defined-outside-init", args=attr, node=node
                        )