# Buggy code
def visit_member_expr(self, expr: MemberExpr) -> None:
    base = expr.expr
    base.accept(self)
    # Bind references to module attributes.
    if isinstance(base, RefExpr) and base.kind == MODULE_REF:
        file = cast(MypyFile, base.node)
        n = file.names.get(expr.name, None) if file is not None else None
        if n:
            n = self.normalize_type_alias(n, expr)
            if not n:
                return
            expr.kind = n.kind
            expr.fullname = n.fullname
            expr.node = n.node
        else:
            # We only catch some errors here; the rest will be
            # catched during type checking.
            #
            # This way we can report a larger number of errors in
            # one type checker run. If we reported errors here,
            # the build would terminate after semantic analysis
            # and we wouldn't be able to report any type errors.
            full_name = "%s.%s" % (
                file.fullname() if file is not None else None,
                expr.name,
            )
            if full_name in obsolete_name_mapping:
                self.fail(
                    "Module has no attribute %r (it's now called %r)"
                    % (expr.name, obsolete_name_mapping[full_name]),
                    expr,
                )


# Traceback (AttributeError)
Traceback (most recent call last):
File "C:\Users\fred\Anaconda3\Scripts\mypy", line 6, in <module>
main(__file__)
File "C:\Users\fred\Anaconda3\lib\site-packages\mypy\main.py", line 54, in main
res = type_check_only(sources, bin_dir, options)
File "C:\Users\fred\Anaconda3\lib\site-packages\mypy\main.py", line 102, in type_check_only
python_path=options.python_path)
File "C:\Users\fred\Anaconda3\lib\site-packages\mypy\build.py", line 211, in build
dispatch(sources, manager)
File "C:\Users\fred\Anaconda3\lib\site-packages\mypy\build.py", line 1336, in dispatch
process_graph(graph, manager)
File "C:\Users\fred\Anaconda3\lib\site-packages\mypy\build.py", line 1467, in process_graph
process_stale_scc(graph, scc)
File "C:\Users\fred\Anaconda3\lib\site-packages\mypy\build.py", line 1497, in process_stale_scc
graph[id].type_check()
File "C:\Users\fred\Anaconda3\lib\site-packages\mypy\build.py", line 1316, in type_check
manager.type_checker.visit_file(self.tree, self.xpath)
File "C:\Users\fred\Anaconda3\lib\site-packages\mypy\checker.py", line 426, in visit_file
self.accept(d)
File "C:\Users\fred\Anaconda3\lib\site-packages\mypy\checker.py", line 476, in accept
typ = node.accept(self)
File "C:\Users\fred\Anaconda3\lib\site-packages\mypy\nodes.py", line 531, in accept
return visitor.visit_decorator(self)
File "C:\Users\fred\Anaconda3\lib\site-packages\mypy\checker.py", line 1956, in visit_decorator
dec = self.accept(d)
File "C:\Users\fred\Anaconda3\lib\site-packages\mypy\checker.py", line 476, in accept
typ = node.accept(self)
File "C:\Users\fred\Anaconda3\lib\site-packages\mypy\nodes.py", line 1185, in accept
return visitor.visit_call_expr(self)
File "C:\Users\fred\Anaconda3\lib\site-packages\mypy\checker.py", line 2009, in visit_call_expr
return self.expr_checker.visit_call_expr(e)
File "C:\Users\fred\Anaconda3\lib\site-packages\mypy\checkexpr.py", line 135, in visit_call_expr
callee_type = self.accept(e.callee)
File "C:\Users\fred\Anaconda3\lib\site-packages\mypy\checkexpr.py", line 1531, in accept
return self.chk.accept(node, context)
File "C:\Users\fred\Anaconda3\lib\site-packages\mypy\checker.py", line 476, in accept
typ = node.accept(self)
File "C:\Users\fred\Anaconda3\lib\site-packages\mypy\nodes.py", line 1141, in accept
return visitor.visit_member_expr(self)
File "C:\Users\fred\Anaconda3\lib\site-packages\mypy\checker.py", line 2053, in visit_member_expr
return self.expr_checker.visit_member_expr(e)
File "C:\Users\fred\Anaconda3\lib\site-packages\mypy\checkexpr.py", line 836, in visit_member_expr
result = self.analyze_ordinary_member_access(e, False)
File "C:\Users\fred\Anaconda3\lib\site-packages\mypy\checkexpr.py", line 847, in analyze_ordinary_member_access
return analyze_member_access(e.name, self.accept(e.expr), e,
File "C:\Users\fred\Anaconda3\lib\site-packages\mypy\checkexpr.py", line 1531, in accept
return self.chk.accept(node, context)
File "C:\Users\fred\Anaconda3\lib\site-packages\mypy\checker.py", line 476, in accept
typ = node.accept(self)
File "C:\Users\fred\Anaconda3\lib\site-packages\mypy\nodes.py", line 1141, in accept
return visitor.visit_member_expr(self)
File "C:\Users\fred\Anaconda3\lib\site-packages\mypy\checker.py", line 2053, in visit_member_expr
return self.expr_checker.visit_member_expr(e)
File "C:\Users\fred\Anaconda3\lib\site-packages\mypy\checkexpr.py", line 836, in visit_member_expr
result = self.analyze_ordinary_member_access(e, False)
File "C:\Users\fred\Anaconda3\lib\site-packages\mypy\checkexpr.py", line 849, in analyze_ordinary_member_access
self.named_type, self.not_ready_callback, self.msg)
File "C:\Users\fred\Anaconda3\lib\site-packages\mypy\checkmember.py", line 96, in analyze_member_access
builtin_type, not_ready_callback, msg)
File "C:\Users\fred\Anaconda3\lib\site-packages\mypy\checkmember.py", line 319, in analyze_class_attribute_access
return function_type(cast(FuncBase, node.node), builtin_type('builtins.function'))
File "C:\Users\fred\Anaconda3\lib\site-packages\mypy\nodes.py", line 2129, in function_type
if func.type:
AttributeError: 'MypyFile' object has no attribute 'type'

# Fixed code
def visit_member_expr(self, expr: MemberExpr) -> None:
    base = expr.expr
    base.accept(self)
    # Bind references to module attributes.
    if isinstance(base, RefExpr) and base.kind == MODULE_REF:
        # This branch handles the case foo.bar where foo is a module.
        # In this case base.node is the module's MypyFile and we look up
        # bar in its namespace.  This must be done for all types of bar.
        file = cast(MypyFile, base.node)
        n = file.names.get(expr.name, None) if file is not None else None
        if n:
            n = self.normalize_type_alias(n, expr)
            if not n:
                return
            expr.kind = n.kind
            expr.fullname = n.fullname
            expr.node = n.node
        else:
            # We only catch some errors here; the rest will be
            # catched during type checking.
            #
            # This way we can report a larger number of errors in
            # one type checker run. If we reported errors here,
            # the build would terminate after semantic analysis
            # and we wouldn't be able to report any type errors.
            full_name = "%s.%s" % (
                file.fullname() if file is not None else None,
                expr.name,
            )
            if full_name in obsolete_name_mapping:
                self.fail(
                    "Module has no attribute %r (it's now called %r)"
                    % (expr.name, obsolete_name_mapping[full_name]),
                    expr,
                )
    elif isinstance(base, RefExpr) and isinstance(base.node, TypeInfo):
        # This branch handles the case C.bar where C is a class
        # and bar is a module resulting from `import bar` inside
        # class C.  Here base.node is a TypeInfo, and again we
        # look up the name in its namespace.  This is done only
        # when bar is a module; other things (e.g. methods)
        # are handled by other code in checkmember.
        n = base.node.names.get(expr.name)
        if n is not None and n.kind == MODULE_REF:
            n = self.normalize_type_alias(n, expr)
            if not n:
                return
            expr.kind = n.kind
            expr.fullname = n.fullname
            expr.node = n.node