# Buggy code
def analyze_ref_expr(self, e: RefExpr, lvalue: bool = False) -> Type:
    result = None  # type: Optional[Type]
    node = e.node
    if isinstance(node, Var):
        # Variable reference.
        result = self.analyze_var_ref(node, e)
        if isinstance(result, PartialType):
            if result.type is None:
                # 'None' partial type. It has a well-defined type. In an lvalue context
                # we want to preserve the knowledge of it being a partial type.
                if not lvalue:
                    result = NoneTyp()
            else:
                partial_types = self.chk.find_partial_types(node)
                if partial_types is not None and not self.chk.current_node_deferred:
                    context = partial_types[node]
                    self.msg.fail(messages.NEED_ANNOTATION_FOR_VAR, context)
                result = AnyType(TypeOfAny.special_form)
    elif isinstance(node, FuncDef):
        # Reference to a global function.
        result = function_type(node, self.named_type("builtins.function"))
    elif isinstance(node, OverloadedFuncDef):
        result = node.type
    elif isinstance(node, TypeInfo):
        # Reference to a type object.
        result = type_object_type(node, self.named_type)
        if isinstance(self.type_context[-1], TypeType):
            # This is the type in a Type[] expression, so substitute type
            # variables with Any.
            result = erasetype.erase_typevars(result)
    elif isinstance(node, MypyFile):
        # Reference to a module object.
        try:
            result = self.named_type("types.ModuleType")
        except KeyError:
            # In test cases might 'types' may not be available.
            # Fall back to a dummy 'object' type instead to
            # avoid a crash.
            result = self.named_type("builtins.object")
    elif isinstance(node, Decorator):
        result = self.analyze_var_ref(node.var, e)
    else:
        # Unknown reference; use any type implicitly to avoid
        # generating extra type errors.
        result = AnyType(TypeOfAny.from_error)
    assert result is not None
    return result


# Traceback (AssertionError)
.\break_mypy.py:5: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.511
Traceback (most recent call last):
File "C:\Anaconda3\Scripts\mypy", line 6, in <module>
main(__file__)
File "C:\Anaconda3\lib\site-packages\mypy\main.py", line 46, in main
res = type_check_only(sources, bin_dir, options)
File "C:\Anaconda3\lib\site-packages\mypy\main.py", line 93, in type_check_only
options=options)
File "C:\Anaconda3\lib\site-packages\mypy\build.py", line 188, in build
graph = dispatch(sources, manager)
File "C:\Anaconda3\lib\site-packages\mypy\build.py", line 1595, in dispatch
process_graph(graph, manager)
File "C:\Anaconda3\lib\site-packages\mypy\build.py", line 1838, in process_graph
process_stale_scc(graph, scc, manager)
File "C:\Anaconda3\lib\site-packages\mypy\build.py", line 1937, in process_stale_scc
graph[id].type_check_first_pass()
File "C:\Anaconda3\lib\site-packages\mypy\build.py", line 1510, in type_check_first_pass
self.type_checker.check_first_pass()
File "C:\Anaconda3\lib\site-packages\mypy\checker.py", line 177, in check_first_pass
self.accept(d)
File "C:\Anaconda3\lib\site-packages\mypy\checker.py", line 264, in accept
stmt.accept(self)
File "C:\Anaconda3\lib\site-packages\mypy\nodes.py", line 855, in accept
return visitor.visit_assignment_stmt(self)
File "C:\Anaconda3\lib\site-packages\mypy\checker.py", line 1180, in visit_assignment_stmt
self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
File "C:\Anaconda3\lib\site-packages\mypy\checker.py", line 1260, in check_assignment
self.infer_variable_type(inferred, lvalue, self.expr_checker.accept(rvalue),
File "C:\Anaconda3\lib\site-packages\mypy\checkexpr.py", line 2058, in accept
typ = node.accept(self)
File "C:\Anaconda3\lib\site-packages\mypy\nodes.py", line 1215, in accept
return visitor.visit_name_expr(self)
File "C:\Anaconda3\lib\site-packages\mypy\checkexpr.py", line 122, in visit_name_expr
result = self.analyze_ref_expr(e)
File "C:\Anaconda3\lib\site-packages\mypy\checkexpr.py", line 160, in analyze_ref_expr
assert result is not None
AssertionError:

# Fixed code
def analyze_ref_expr(self, e: RefExpr, lvalue: bool = False) -> Type:
    result = None  # type: Optional[Type]
    node = e.node
    if isinstance(node, Var):
        # Variable reference.
        result = self.analyze_var_ref(node, e)
        if isinstance(result, PartialType):
            if result.type is None:
                # 'None' partial type. It has a well-defined type. In an lvalue context
                # we want to preserve the knowledge of it being a partial type.
                if not lvalue:
                    result = NoneTyp()
            else:
                partial_types = self.chk.find_partial_types(node)
                if partial_types is not None and not self.chk.current_node_deferred:
                    context = partial_types[node]
                    self.msg.fail(messages.NEED_ANNOTATION_FOR_VAR, context)
                result = AnyType(TypeOfAny.special_form)
    elif isinstance(node, FuncDef):
        # Reference to a global function.
        result = function_type(node, self.named_type("builtins.function"))
    elif isinstance(node, OverloadedFuncDef) and node.type is not None:
        # node.type is None when there are multiple definitions of a function
        # and it's decorated by somthing that is not typing.overload
        result = node.type
    elif isinstance(node, TypeInfo):
        # Reference to a type object.
        result = type_object_type(node, self.named_type)
        if isinstance(self.type_context[-1], TypeType):
            # This is the type in a Type[] expression, so substitute type
            # variables with Any.
            result = erasetype.erase_typevars(result)
    elif isinstance(node, MypyFile):
        # Reference to a module object.
        try:
            result = self.named_type("types.ModuleType")
        except KeyError:
            # In test cases might 'types' may not be available.
            # Fall back to a dummy 'object' type instead to
            # avoid a crash.
            result = self.named_type("builtins.object")
    elif isinstance(node, Decorator):
        result = self.analyze_var_ref(node.var, e)
    else:
        # Unknown reference; use any type implicitly to avoid
        # generating extra type errors.
        result = AnyType(TypeOfAny.from_error)
    assert result is not None
    return result