# Buggy code
def array_raw_callback(ctx: "mypy.plugin.AttributeContext") -> Type:
    """Callback to provide an accurate type for ctypes.Array.raw."""
    et = _get_array_element_type(ctx.type)
    if et is not None:
        types = []  # type: List[Type]
        for tp in union_items(et):
            if (
                isinstance(tp, AnyType)
                or isinstance(tp, Instance)
                and tp.type.fullname() == "ctypes.c_char"
            ):
                types.append(ctx.api.named_generic_type("builtins.bytes", []))
            else:
                ctx.api.msg.fail(
                    'ctypes.Array attribute "raw" is only available'
                    ' with element type c_char, not "{}"'.format(et),
                    ctx.context,
                )
        return UnionType.make_simplified_union(types)
    return ctx.default_attr_type


# Traceback (AssertionError)
Traceback (most recent call last):
File "C:\Python36\Scripts\mypy-script.py", line 11, in <module>
load_entry_point('mypy==0.650+dev.3ad628d797defcbd892dede48151c8e390f45258', 'console_scripts', 'mypy')()
File "c:\python36\lib\site-packages\mypy\__main__.py", line 7, in console_entry
main(None)
File "c:\python36\lib\site-packages\mypy\main.py", line 92, in main
res = build.build(sources, options, None, flush_errors, fscache)
File "c:\python36\lib\site-packages\mypy\build.py", line 156, in build
result = _build(sources, options, alt_lib_path, flush_errors, fscache)
File "c:\python36\lib\site-packages\mypy\build.py", line 206, in _build
graph = dispatch(sources, manager)
File "c:\python36\lib\site-packages\mypy\build.py", line 2230, in dispatch
process_graph(graph, manager)
File "c:\python36\lib\site-packages\mypy\build.py", line 2530, in process_graph
process_stale_scc(graph, scc, manager)
File "c:\python36\lib\site-packages\mypy\build.py", line 2653, in process_stale_scc
graph[id].type_check_first_pass()
File "c:\python36\lib\site-packages\mypy\build.py", line 1788, in type_check_first_pass
self.type_checker().check_first_pass()
File "c:\python36\lib\site-packages\mypy\checker.py", line 282, in check_first_pass
self.accept(d)
File "c:\python36\lib\site-packages\mypy\checker.py", line 393, in accept
stmt.accept(self)
File "c:\python36\lib\site-packages\mypy\nodes.py", line 848, in accept
return visitor.visit_class_def(self)
File "c:\python36\lib\site-packages\mypy\checker.py", line 1536, in visit_class_def
self.accept(defn.defs)
File "c:\python36\lib\site-packages\mypy\checker.py", line 393, in accept
stmt.accept(self)
File "c:\python36\lib\site-packages\mypy\nodes.py", line 913, in accept
return visitor.visit_block(self)
File "c:\python36\lib\site-packages\mypy\checker.py", line 1688, in visit_block
self.accept(s)
File "c:\python36\lib\site-packages\mypy\checker.py", line 393, in accept
stmt.accept(self)
File "c:\python36\lib\site-packages\mypy\nodes.py", line 611, in accept
return visitor.visit_func_def(self)
File "c:\python36\lib\site-packages\mypy\checker.py", line 704, in visit_func_def
self._visit_func_def(defn)
File "c:\python36\lib\site-packages\mypy\checker.py", line 708, in _visit_func_def
self.check_func_item(defn, name=defn.name())
File "c:\python36\lib\site-packages\mypy\checker.py", line 770, in check_func_item
self.check_func_def(defn, typ, name)
File "c:\python36\lib\site-packages\mypy\checker.py", line 934, in check_func_def
self.accept(item.body)
File "c:\python36\lib\site-packages\mypy\checker.py", line 393, in accept
stmt.accept(self)
File "c:\python36\lib\site-packages\mypy\nodes.py", line 913, in accept
return visitor.visit_block(self)
File "c:\python36\lib\site-packages\mypy\checker.py", line 1688, in visit_block
self.accept(s)
File "c:\python36\lib\site-packages\mypy\checker.py", line 393, in accept
stmt.accept(self)
File "c:\python36\lib\site-packages\mypy\nodes.py", line 1046, in accept
return visitor.visit_return_stmt(self)
File "c:\python36\lib\site-packages\mypy\checker.py", line 2627, in visit_return_stmt
self.check_return_stmt(s)
File "c:\python36\lib\site-packages\mypy\checker.py", line 2660, in check_return_stmt
allow_none_return=allow_none_func_call)
File "c:\python36\lib\site-packages\mypy\checkexpr.py", line 3060, in accept
typ = node.accept(self)
File "c:\python36\lib\site-packages\mypy\nodes.py", line 1754, in accept
return visitor.visit_tuple_expr(self)
File "c:\python36\lib\site-packages\mypy\checkexpr.py", line 2619, in visit_tuple_expr
tt = self.accept(item, type_context_items[j])
File "c:\python36\lib\site-packages\mypy\checkexpr.py", line 3060, in accept
typ = node.accept(self)
File "c:\python36\lib\site-packages\mypy\nodes.py", line 1421, in accept
return visitor.visit_call_expr(self)
File "c:\python36\lib\site-packages\mypy\checkexpr.py", line 229, in visit_call_expr
return self.visit_call_expr_inner(e, allow_none_return=allow_none_return)
File "c:\python36\lib\site-packages\mypy\checkexpr.py", line 271, in visit_call_expr_inner
callee_type = self.accept(e.callee, type_context, always_allow_any=True)
File "c:\python36\lib\site-packages\mypy\checkexpr.py", line 3060, in accept
typ = node.accept(self)
File "c:\python36\lib\site-packages\mypy\nodes.py", line 1373, in accept
return visitor.visit_member_expr(self)
File "c:\python36\lib\site-packages\mypy\checkexpr.py", line 1687, in visit_member_expr
result = self.analyze_ordinary_member_access(e, is_lvalue)
File "c:\python36\lib\site-packages\mypy\checkexpr.py", line 1698, in analyze_ordinary_member_access
original_type = self.accept(e.expr)
File "c:\python36\lib\site-packages\mypy\checkexpr.py", line 3060, in accept
typ = node.accept(self)
File "c:\python36\lib\site-packages\mypy\nodes.py", line 1373, in accept
return visitor.visit_member_expr(self)
File "c:\python36\lib\site-packages\mypy\checkexpr.py", line 1687, in visit_member_expr
result = self.analyze_ordinary_member_access(e, is_lvalue)
File "c:\python36\lib\site-packages\mypy\checkexpr.py", line 1702, in analyze_ordinary_member_access
original_type=original_type, chk=self.chk)
File "c:\python36\lib\site-packages\mypy\checkmember.py", line 105, in analyze_member_access
original_type=original_type, chk=chk)
File "c:\python36\lib\site-packages\mypy\checkmember.py", line 282, in analyze_member_var_access
chk=chk, implicit=implicit)
File "c:\python36\lib\site-packages\mypy\checkmember.py", line 474, in analyze_var
result = hook(AttributeContext(original_type, result, node, chk))
File "c:\python36\lib\site-packages\mypy\plugins\ctypes.py", line 173, in array_value_callback
types.append(ctx.api.named_generic_type('builtins.bytes', []))
File "c:\python36\lib\site-packages\mypy\checker.py", line 3501, in named_generic_type
info = self.lookup_typeinfo(name)
File "c:\python36\lib\site-packages\mypy\checker.py", line 3509, in lookup_typeinfo
assert isinstance(node, TypeInfo)
AssertionError:

# Fixed code
def array_raw_callback(ctx: "mypy.plugin.AttributeContext") -> Type:
    """Callback to provide an accurate type for ctypes.Array.raw."""
    et = _get_array_element_type(ctx.type)
    if et is not None:
        types = []  # type: List[Type]
        for tp in union_items(et):
            if (
                isinstance(tp, AnyType)
                or isinstance(tp, Instance)
                and tp.type.fullname() == "ctypes.c_char"
            ):
                types.append(_get_bytes_type(ctx.api))
            else:
                ctx.api.msg.fail(
                    'ctypes.Array attribute "raw" is only available'
                    ' with element type c_char, not "{}"'.format(et),
                    ctx.context,
                )
        return UnionType.make_simplified_union(types)
    return ctx.default_attr_type