# Buggy code
def visit_Subscript(self, n: ast35.Subscript) -> Type:
    if not isinstance(n.slice, ast35.Index):
        self.fail(TYPE_COMMENT_SYNTAX_ERROR, self.line, getattr(n, "col_offset", -1))
        return AnyType()

    value = self.visit(n.value)

    assert isinstance(value, UnboundType)
    assert not value.args

    empty_tuple_index = False
    if isinstance(n.slice.value, ast35.Tuple):
        params = self.translate_expr_list(n.slice.value.elts)
        if len(n.slice.value.elts) == 0:
            empty_tuple_index = True
    else:
        params = [self.visit(n.slice.value)]

    return UnboundType(
        value.name, params, line=self.line, empty_tuple_index=empty_tuple_index
    )


# Traceback (AssertionError)
Traceback (most recent call last):
File "/usr/local/bin/mypy", line 6, in <module>
main(__file__)
File "/usr/local/lib/python3.4/dist-packages/mypy/main.py", line 42, in main
res = type_check_only(sources, bin_dir, options)
File "/usr/local/lib/python3.4/dist-packages/mypy/main.py", line 86, in type_check_only
options=options)
File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 183, in build
dispatch(sources, manager)
File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1523, in dispatch
graph = load_graph(sources, manager)
File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1605, in load_graph
root_source=True)
File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1212, in __init__
self.parse_file()
File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1376, in parse_file
self.ignore_all or self.options.ignore_errors)
File "/usr/lib/python3.4/contextlib.py", line 77, in __exit__
self.gen.throw(type, value, traceback)
File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1293, in wrap_context
yield
File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1376, in parse_file
self.ignore_all or self.options.ignore_errors)
File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 462, in parse_file
tree = parse(source, path, self.errors, options=self.options)
File "/usr/local/lib/python3.4/dist-packages/mypy/parse.py", line 96, in parse
custom_typing_module=options.custom_typing_module)
File "/usr/local/lib/python3.4/dist-packages/mypy/fastparse.py", line 74, in parse
).visit(ast)
File "/usr/local/lib/python3.4/dist-packages/typed_ast-0.6.3-py3.4-linux-x86_64.egg/typed_ast/ast35.py", line 256, in visit
return visitor(node)
File "/usr/local/lib/python3.4/dist-packages/mypy/fastparse.py", line 257, in visit_Module
body = self.fix_function_overloads(self.translate_stmt_list(mod.body))
File "/usr/local/lib/python3.4/dist-packages/mypy/fastparse.py", line 157, in translate_stmt_list
stmt = self.visit(e)
File "/usr/local/lib/python3.4/dist-packages/typed_ast-0.6.3-py3.4-linux-x86_64.egg/typed_ast/ast35.py", line 256, in visit
return visitor(node)
File "/usr/local/lib/python3.4/dist-packages/mypy/fastparse.py", line 101, in wrapper
node = f(self, ast)
File "/usr/local/lib/python3.4/dist-packages/mypy/fastparse.py", line 502, in visit_Assign
typ = TypeConverter(self.errors, line=n.lineno).visit(n.annotation)  # type: ignore
File "/usr/local/lib/python3.4/dist-packages/typed_ast-0.6.3-py3.4-linux-x86_64.egg/typed_ast/ast35.py", line 256, in visit
return visitor(node)
File "/usr/local/lib/python3.4/dist-packages/mypy/fastparse.py", line 968, in visit_Subscript
params = [self.visit(n.slice.value)]
File "/usr/local/lib/python3.4/dist-packages/typed_ast-0.6.3-py3.4-linux-x86_64.egg/typed_ast/ast35.py", line 256, in visit
return visitor(node)
File "/usr/local/lib/python3.4/dist-packages/mypy/fastparse.py", line 979, in visit_Attribute
assert isinstance(before_dot, UnboundType)
AssertionError:

# Fixed code
def visit_Subscript(self, n: ast35.Subscript) -> Type:
    if not isinstance(n.slice, ast35.Index):
        self.fail(TYPE_COMMENT_SYNTAX_ERROR, self.line, getattr(n, "col_offset", -1))
        return AnyType()

    empty_tuple_index = False
    if isinstance(n.slice.value, ast35.Tuple):
        params = self.translate_expr_list(n.slice.value.elts)
        if len(n.slice.value.elts) == 0:
            empty_tuple_index = True
    else:
        params = [self.visit(n.slice.value)]

    value = self.visit(n.value)
    if isinstance(value, UnboundType) and not value.args:
        return UnboundType(
            value.name, params, line=self.line, empty_tuple_index=empty_tuple_index
        )
    else:
        self.fail(TYPE_COMMENT_AST_ERROR, self.line, getattr(n, "col_offset", -1))
        return AnyType()