# Buggy code
def infer_enum_class(node):
    """Specific inference for enums."""
    names = set(("Enum", "IntEnum", "enum.Enum", "enum.IntEnum"))
    for basename in node.basenames:
        # TODO: doesn't handle subclasses yet. This implementation
        # is a hack to support enums.
        if basename not in names:
            continue
        if node.root().name == "enum":
            # Skip if the class is directly from enum module.
            break
        for local, values in node.locals.items():
            if any(not isinstance(value, nodes.AssignName) for value in values):
                continue

            stmt = values[0].statement()
            if isinstance(stmt.targets[0], nodes.Tuple):
                targets = stmt.targets[0].itered()
            else:
                targets = stmt.targets

            new_targets = []
            for target in targets:
                # Replace all the assignments with our mocked class.
                classdef = dedent(
                    """
                class %(name)s(%(types)s):
                    @property
                    def value(self):
                        # Not the best return.
                        return None
                    @property
                    def name(self):
                        return %(name)r
                """
                    % {"name": target.name, "types": ", ".join(node.basenames)}
                )
                fake = AstroidBuilder(MANAGER).string_build(classdef)[target.name]
                fake.parent = target.parent
                for method in node.mymethods():
                    fake.locals[method.name] = [method]
                new_targets.append(fake.instantiate_class())
            node.locals[local] = new_targets
        break
    return node


# Traceback (AttributeError)
Traceback (most recent call last):
File "/Users/jeff/.virtualenvs/v6/lib/python3.6/site-packages/pylint/lint.py", line 896, in get_ast
return MANAGER.ast_from_file(filepath, modname, source=True)
File "/Users/jeff/.virtualenvs/v6/lib/python3.6/site-packages/astroid/manager.py", line 80, in ast_from_file
return AstroidBuilder(self).file_build(filepath, modname)
File "/Users/jeff/.virtualenvs/v6/lib/python3.6/site-packages/astroid/builder.py", line 152, in file_build
return self._post_build(module, encoding)
File "/Users/jeff/.virtualenvs/v6/lib/python3.6/site-packages/astroid/builder.py", line 176, in _post_build
module = self._manager.visit_transforms(module)
File "/Users/jeff/.virtualenvs/v6/lib/python3.6/site-packages/astroid/manager.py", line 62, in visit_transforms
return self._transform.visit(node)
File "/Users/jeff/.virtualenvs/v6/lib/python3.6/site-packages/astroid/transforms.py", line 83, in visit
module.body = [self._visit(child) for child in module.body]
File "/Users/jeff/.virtualenvs/v6/lib/python3.6/site-packages/astroid/transforms.py", line 83, in <listcomp>
module.body = [self._visit(child) for child in module.body]
File "/Users/jeff/.virtualenvs/v6/lib/python3.6/site-packages/astroid/transforms.py", line 53, in _visit
return self._transform(node)
File "/Users/jeff/.virtualenvs/v6/lib/python3.6/site-packages/astroid/transforms.py", line 36, in _transform
ret = transform_func(node)
File "/Users/jeff/.virtualenvs/v6/lib/python3.6/site-packages/astroid/brain/brain_namedtuple_enum.py", line 201, in infer_enum_class
if isinstance(stmt.targets[0], nodes.Tuple):
AttributeError: 'AnnAssign' object has no attribute 'targets'
************* Module tmp
F:  1, 0: <class 'AttributeError'>: 'AnnAssign' object has no attribute 'targets' (astroid-error)

# Fixed code
def infer_enum_class(node):
    """Specific inference for enums."""
    names = set(("Enum", "IntEnum", "enum.Enum", "enum.IntEnum"))
    for basename in node.basenames:
        # TODO: doesn't handle subclasses yet. This implementation
        # is a hack to support enums.
        if basename not in names:
            continue
        if node.root().name == "enum":
            # Skip if the class is directly from enum module.
            break
        for local, values in node.locals.items():
            if any(not isinstance(value, nodes.AssignName) for value in values):
                continue

            stmt = values[0].statement()
            if isinstance(stmt, nodes.Assign):
                if isinstance(stmt.targets[0], nodes.Tuple):
                    targets = stmt.targets[0].itered()
                else:
                    targets = stmt.targets
            elif isinstance(stmt, nodes.AnnAssign):
                targets = [stmt.target]

            new_targets = []
            for target in targets:
                # Replace all the assignments with our mocked class.
                classdef = dedent(
                    """
                class %(name)s(%(types)s):
                    @property
                    def value(self):
                        # Not the best return.
                        return None
                    @property
                    def name(self):
                        return %(name)r
                """
                    % {"name": target.name, "types": ", ".join(node.basenames)}
                )
                fake = AstroidBuilder(MANAGER).string_build(classdef)[target.name]
                fake.parent = target.parent
                for method in node.mymethods():
                    fake.locals[method.name] = [method]
                new_targets.append(fake.instantiate_class())
            node.locals[local] = new_targets
        break
    return node