# Buggy code
def check_lvalue(
    self, lvalue: Lvalue
) -> Tuple[Optional[Type], Optional[IndexExpr], Optional[Var]]:
    lvalue_type = None  # type: Optional[Type]
    index_lvalue = None  # type: Optional[IndexExpr]
    inferred = None  # type: Optional[Var]

    if self.is_definition(lvalue):
        if isinstance(lvalue, NameExpr):
            inferred = cast(Var, lvalue.node)
            assert isinstance(inferred, Var)
        else:
            assert isinstance(lvalue, MemberExpr)
            self.expr_checker.accept(lvalue.expr)
            inferred = lvalue.def_var
    elif isinstance(lvalue, IndexExpr):
        index_lvalue = lvalue
    elif isinstance(lvalue, MemberExpr):
        lvalue_type = self.expr_checker.analyze_ordinary_member_access(lvalue, True)
        self.store_type(lvalue, lvalue_type)
    elif isinstance(lvalue, NameExpr):
        lvalue_type = self.expr_checker.analyze_ref_expr(lvalue, lvalue=True)
        self.store_type(lvalue, lvalue_type)
    elif isinstance(lvalue, TupleExpr) or isinstance(lvalue, ListExpr):
        types = [self.check_lvalue(sub_expr)[0] for sub_expr in lvalue.items]
        lvalue_type = TupleType(types, self.named_type("builtins.tuple"))
    else:
        lvalue_type = self.expr_checker.accept(lvalue)

    return lvalue_type, index_lvalue, inferred


# Traceback (AttributeError)
Traceback (most recent call last):
File "/Users/ambv/.venvs/mypy/bin/mypy", line 11, in <module>
load_entry_point('mypy', 'console_scripts', 'mypy')()
File "mypy/__main__.py", line 7, in console_entry
main(None)
File "mypy/main.py", line 50, in main
res = type_check_only(sources, bin_dir, options)
File "mypy/main.py", line 103, in type_check_only
options=options)
File "mypy/build.py", line 198, in build
graph = dispatch(sources, manager)
File "mypy/build.py", line 1841, in dispatch
process_graph(graph, manager)
File "mypy/build.py", line 2091, in process_graph
process_stale_scc(graph, scc, manager)
File "mypy/build.py", line 2194, in process_stale_scc
graph[id].type_check_first_pass()
File "mypy/build.py", line 1753, in type_check_first_pass
self.type_checker.check_first_pass()
File "mypy/checker.py", line 194, in check_first_pass
self.accept(d)
File "mypy/checker.py", line 282, in accept
stmt.accept(self)
File "mypy/nodes.py", line 519, in accept
return visitor.visit_func_def(self)
File "mypy/checker.py", line 530, in visit_func_def
self.check_func_item(defn, name=defn.name())
File "mypy/checker.py", line 590, in check_func_item
self.check_func_def(defn, typ, name)
File "mypy/checker.py", line 750, in check_func_def
self.accept(item.body)
File "mypy/checker.py", line 282, in accept
stmt.accept(self)
File "mypy/nodes.py", line 773, in accept
return visitor.visit_block(self)
File "mypy/checker.py", line 1304, in visit_block
self.accept(s)
File "mypy/checker.py", line 282, in accept
stmt.accept(self)
File "mypy/nodes.py", line 817, in accept
return visitor.visit_assignment_stmt(self)
File "mypy/checker.py", line 1311, in visit_assignment_stmt
self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
File "mypy/checker.py", line 1339, in check_assignment
infer_lvalue_type)
File "mypy/checker.py", line 1589, in check_assignment_to_multiple_lvalues
self.check_multi_assignment(lvalues, rvalue, context, infer_lvalue_type)
File "mypy/checker.py", line 1630, in check_multi_assignment
context, undefined_rvalue, infer_lvalue_type)
File "mypy/checker.py", line 1650, in check_multi_assignment_from_tuple
reinferred_rvalue_type = self.expr_checker.accept(rvalue, lvalue_type)
File "mypy/checkexpr.py", line 2372, in accept
typ = node.accept(self)
File "mypy/nodes.py", line 1256, in accept
return visitor.visit_call_expr(self)
File "mypy/checkexpr.py", line 266, in visit_call_expr
ret_type = self.check_call_expr_with_callee_type(callee_type, e, fullname, object_type)
File "mypy/checkexpr.py", line 503, in check_call_expr_with_callee_type
object_type=object_type)[0]
File "mypy/checkexpr.py", line 563, in check_call
callee, context)
File "mypy/checkexpr.py", line 752, in infer_function_type_arguments_using_context
erased_ctx = replace_meta_vars(ctx, ErasedType())
File "mypy/erasetype.py", line 94, in replace_meta_vars
return t.accept(TypeVarEraser(lambda id: id.is_meta_var(), target_type))
File "mypy/types.py", line 982, in accept
return visitor.visit_tuple_type(self)
File "mypy/types.py", line 1554, in visit_tuple_type
return TupleType(self.translate_types(t.items),
File "mypy/types.py", line 1574, in translate_types
return [t.accept(self) for t in types]
File "mypy/types.py", line 1574, in <listcomp>
return [t.accept(self) for t in types]
File "mypy/types.py", line 982, in accept
return visitor.visit_tuple_type(self)
File "mypy/types.py", line 1554, in visit_tuple_type
return TupleType(self.translate_types(t.items),
File "mypy/types.py", line 1574, in translate_types
return [t.accept(self) for t in types]
File "mypy/types.py", line 1574, in <listcomp>
return [t.accept(self) for t in types]
AttributeError: 'NoneType' object has no attribute 'accept'
/tmp/test.py:13: : note: use --pdb to drop into pdb

# Fixed code
def check_lvalue(
    self, lvalue: Lvalue
) -> Tuple[Optional[Type], Optional[IndexExpr], Optional[Var]]:
    lvalue_type = None  # type: Optional[Type]
    index_lvalue = None  # type: Optional[IndexExpr]
    inferred = None  # type: Optional[Var]

    if self.is_definition(lvalue):
        if isinstance(lvalue, NameExpr):
            inferred = cast(Var, lvalue.node)
            assert isinstance(inferred, Var)
        else:
            assert isinstance(lvalue, MemberExpr)
            self.expr_checker.accept(lvalue.expr)
            inferred = lvalue.def_var
    elif isinstance(lvalue, IndexExpr):
        index_lvalue = lvalue
    elif isinstance(lvalue, MemberExpr):
        lvalue_type = self.expr_checker.analyze_ordinary_member_access(lvalue, True)
        self.store_type(lvalue, lvalue_type)
    elif isinstance(lvalue, NameExpr):
        lvalue_type = self.expr_checker.analyze_ref_expr(lvalue, lvalue=True)
        self.store_type(lvalue, lvalue_type)
    elif isinstance(lvalue, TupleExpr) or isinstance(lvalue, ListExpr):
        types = [
            self.check_lvalue(sub_expr)[0]
            or
            # This type will be used as a context for further inference of rvalue,
            # we put Uninhabited if there is no information available from lvalue.
            UninhabitedType()
            for sub_expr in lvalue.items
        ]
        lvalue_type = TupleType(types, self.named_type("builtins.tuple"))
    else:
        lvalue_type = self.expr_checker.accept(lvalue)

    return lvalue_type, index_lvalue, inferred