# Buggy code
def analyze_class_attribute_access(
    itype: Instance,
    name: str,
    context: Context,
    is_lvalue: bool,
    builtin_type: Callable[[str], Instance],
    msg: MessageBuilder,
) -> Type:
    node = itype.type.get(name)
    if not node:
        if itype.type.fallback_to_any:
            return AnyType()
        return None

    is_decorated = isinstance(node.node, Decorator)
    is_method = is_decorated or isinstance(node.node, FuncDef)
    if is_lvalue:
        if is_method:
            msg.cant_assign_to_method(context)
        if isinstance(node.node, TypeInfo):
            msg.fail(messages.CANNOT_ASSIGN_TO_TYPE, context)

    if itype.type.is_enum and not (is_lvalue or is_decorated or is_method):
        return itype

    t = node.type
    if t:
        is_classmethod = is_decorated and cast(Decorator, node.node).func.is_class
        return add_class_tvars(t, itype.type, is_classmethod, builtin_type)
    elif isinstance(node.node, Var):
        msg.cannot_determine_type(name, context)
        return AnyType()

    if isinstance(node.node, TypeInfo):
        return type_object_type(cast(TypeInfo, node.node), builtin_type)

    return function_type(cast(FuncBase, node.node), builtin_type("builtins.function"))


# Traceback (AttributeError)
Traceback (most recent call last):
File "/Users/guido/src/mypy/scripts/mypy", line 6, in <module>
main(__file__)
File "/Users/guido/src/mypy/mypy/main.py", line 49, in main
type_check_only(sources, bin_dir, options)
File "/Users/guido/src/mypy/mypy/main.py", line 92, in type_check_only
python_path=options.python_path)
File "/Users/guido/src/mypy/mypy/build.py", line 197, in build
result = manager.process(initial_states)
File "/Users/guido/src/mypy/mypy/build.py", line 379, in process
next.process()
File "/Users/guido/src/mypy/mypy/build.py", line 849, in process
self.type_checker().visit_file(self.tree, self.tree.path)
File "/Users/guido/src/mypy/mypy/checker.py", line 371, in visit_file
self.accept(d)
File "/Users/guido/src/mypy/mypy/checker.py", line 379, in accept
typ = node.accept(self)
File "/Users/guido/src/mypy/mypy/nodes.py", line 552, in accept
return visitor.visit_assignment_stmt(self)
File "/Users/guido/src/mypy/mypy/checker.py", line 953, in visit_assignment_stmt
self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None)
File "/Users/guido/src/mypy/mypy/checker.py", line 981, in check_assignment
self.infer_variable_type(inferred, lvalue, self.accept(rvalue),
File "/Users/guido/src/mypy/mypy/checker.py", line 379, in accept
typ = node.accept(self)
File "/Users/guido/src/mypy/mypy/nodes.py", line 929, in accept
return visitor.visit_member_expr(self)
File "/Users/guido/src/mypy/mypy/checker.py", line 1770, in visit_member_expr
return self.expr_checker.visit_member_expr(e)
File "/Users/guido/src/mypy/mypy/checkexpr.py", line 680, in visit_member_expr
result = self.analyze_ordinary_member_access(e, False)
File "/Users/guido/src/mypy/mypy/checkexpr.py", line 693, in analyze_ordinary_member_access
self.named_type, self.msg)
File "/Users/guido/src/mypy/mypy/checkmember.py", line 84, in analyze_member_access
result = analyze_class_attribute_access(itype, name, node, is_lvalue, builtin_type, msg)
File "/Users/guido/src/mypy/mypy/checkmember.py", line 240, in analyze_class_attribute_access
return function_type(cast(FuncBase, node.node), builtin_type('builtins.function'))
File "/Users/guido/src/mypy/mypy/nodes.py", line 1733, in function_type
if func.type:
AttributeError: 'Decorator' object has no attribute 'type'

*** INTERNAL ERROR ***

ui/common/uikit.py:64: error: Internal error -- please report a bug at https://github.com/JukkaL/mypy/issues

# Fixed code
def analyze_class_attribute_access(
    itype: Instance,
    name: str,
    context: Context,
    is_lvalue: bool,
    builtin_type: Callable[[str], Instance],
    msg: MessageBuilder,
) -> Type:
    node = itype.type.get(name)
    if not node:
        if itype.type.fallback_to_any:
            return AnyType()
        return None

    is_decorated = isinstance(node.node, Decorator)
    is_method = is_decorated or isinstance(node.node, FuncDef)
    if is_lvalue:
        if is_method:
            msg.cant_assign_to_method(context)
        if isinstance(node.node, TypeInfo):
            msg.fail(messages.CANNOT_ASSIGN_TO_TYPE, context)

    if itype.type.is_enum and not (is_lvalue or is_decorated or is_method):
        return itype

    t = node.type
    if t:
        is_classmethod = is_decorated and cast(Decorator, node.node).func.is_class
        return add_class_tvars(t, itype.type, is_classmethod, builtin_type)
    elif isinstance(node.node, Var):
        msg.cannot_determine_type(name, context)
        return AnyType()

    if isinstance(node.node, TypeInfo):
        return type_object_type(cast(TypeInfo, node.node), builtin_type)

    if is_decorated:
        # TODO: Return type of decorated function. This is quick hack to work around #998.
        return AnyType()
    else:
        return function_type(
            cast(FuncBase, node.node), builtin_type("builtins.function")
        )