# Buggy code
def visit_tuple_expr(self, e: TupleExpr) -> Type:
    """Type check a tuple expression."""
    ctx = None  # type: TupleType
    # Try to determine type context for type inference.
    if isinstance(self.chk.type_context[-1], TupleType):
        t = self.chk.type_context[-1]
        if len(t.items) == len(e.items):
            ctx = t
    # Infer item types.
    items = []  # type: List[Type]
    for i in range(len(e.items)):
        item = e.items[i]
        tt = None  # type: Type
        if not ctx:
            tt = self.accept(item)
        else:
            tt = self.accept(item, ctx.items[i])
        self.check_not_void(tt, e)
        items.append(tt)
    fallback_item = join.join_type_list(items)
    return TupleType(
        items, self.chk.named_generic_type("builtins.tuple", [fallback_item])
    )


# Traceback (AttributeError)
Traceback (most recent call last):
File "/home/dominik/.virtualenvs/mypy/bin/mypy", line 6, in <module>
main(__file__)
File "/home/dominik/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/main.py", line 54, in main
res = type_check_only(sources, bin_dir, options)
File "/home/dominik/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/main.py", line 102, in type_check_only
python_path=options.python_path)
File "/home/dominik/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/build.py", line 211, in build
dispatch(sources, manager)
File "/home/dominik/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/build.py", line 1336, in dispatch
process_graph(graph, manager)
File "/home/dominik/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/build.py", line 1467, in process_graph
process_stale_scc(graph, scc)
File "/home/dominik/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/build.py", line 1497, in process_stale_scc
graph[id].type_check()
File "/home/dominik/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/build.py", line 1316, in type_check
manager.type_checker.visit_file(self.tree, self.xpath)
File "/home/dominik/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/checker.py", line 426, in visit_file
self.accept(d)
File "/home/dominik/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/checker.py", line 476, in accept
typ = node.accept(self)
File "/home/dominik/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/nodes.py", line 729, in accept
return visitor.visit_expression_stmt(self)
File "/home/dominik/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/checker.py", line 1582, in visit_expression_stmt
self.accept(s.expr)
File "/home/dominik/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/checker.py", line 476, in accept
typ = node.accept(self)
File "/home/dominik/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/nodes.py", line 1434, in accept
return visitor.visit_list_expr(self)
File "/home/dominik/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/checker.py", line 2122, in visit_list_expr
return self.expr_checker.visit_list_expr(e)
File "/home/dominik/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/checkexpr.py", line 1251, in visit_list_expr
e)
File "/home/dominik/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/checkexpr.py", line 1270, in check_list_or_set_expr
[nodes.ARG_POS] * len(items), context)[0]
File "/home/dominik/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/checkexpr.py", line 242, in check_call
messages=arg_messages)
File "/home/dominik/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/checkexpr.py", line 661, in check_argument_types
actual + 1, i + 1, callee, context, messages)
File "/home/dominik/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/checkexpr.py", line 686, in check_arg
elif not is_subtype(caller_type, callee_type):
File "/home/dominik/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/subtypes.py", line 49, in is_subtype
return left.accept(SubtypeVisitor(right, type_parameter_checker))
AttributeError: 'NoneType' object has no attribute 'accept'

# Fixed code
def visit_tuple_expr(self, e: TupleExpr) -> Type:
    """Type check a tuple expression."""
    ctx = None  # type: TupleType
    # Try to determine type context for type inference.
    if isinstance(self.chk.type_context[-1], TupleType):
        t = self.chk.type_context[-1]
        ctx = t
    # NOTE: it's possible for the context to have a different
    # number of items than e.  In that case we use those context
    # items that match a position in e, and we'll worry about type
    # mismatches later.

    # Infer item types.  Give up if there's a star expression
    # that's not a Tuple.
    items = []  # type: List[Type]
    j = 0  # Index into ctx.items; irrelevant if ctx is None.
    for i in range(len(e.items)):
        item = e.items[i]
        tt = None  # type: Type
        if isinstance(item, StarExpr):
            # Special handling for star expressions.
            # TODO: If there's a context, and item.expr is a
            # TupleExpr, flatten it, so we can benefit from the
            # context?  Counterargument: Why would anyone write
            # (1, *(2, 3)) instead of (1, 2, 3) except in a test?
            tt = self.accept(item.expr)
            self.check_not_void(tt, e)
            if isinstance(tt, TupleType):
                items.extend(tt.items)
                j += len(tt.items)
            else:
                # A star expression that's not a Tuple.
                # Treat the whole thing as a variable-length tuple.
                return self.check_lst_expr(e.items, "builtins.tuple", "<tuple>", e)
        else:
            if not ctx or j >= len(ctx.items):
                tt = self.accept(item)
            else:
                tt = self.accept(item, ctx.items[j])
                j += 1
            self.check_not_void(tt, e)
            items.append(tt)
    fallback_item = join.join_type_list(items)
    return TupleType(
        items, self.chk.named_generic_type("builtins.tuple", [fallback_item])
    )