# Buggy code
def format_bare(self, typ: Type, verbosity: int = 0) -> str:
    """
    Convert a type to a relatively short string suitable for error messages.

    This method will return an unquoted string.  If a caller doesn't need to
    perform post-processing on the string output, .format should be used
    instead.  (The caller may want to use .quote_type_string after
    processing has happened, to maintain consistent quoting in messages.)
    """
    if isinstance(typ, Instance):
        itype = typ
        # Get the short name of the type.
        if itype.type.fullname() in (
            "types.ModuleType",
            "_importlib_modulespec.ModuleType",
        ):
            # Make some common error messages simpler and tidier.
            return "Module"
        if verbosity >= 2:
            base_str = itype.type.fullname()
        else:
            base_str = itype.type.name()
        if itype.args == []:
            # No type arguments, just return the type name
            return base_str
        elif itype.type.fullname() == "builtins.tuple":
            item_type_str = self.format_bare(itype.args[0])
            return "Tuple[{}, ...]".format(item_type_str)
        elif itype.type.fullname() in reverse_type_aliases:
            alias = reverse_type_aliases[itype.type.fullname()]
            alias = alias.split(".")[-1]
            items = [self.format_bare(arg) for arg in itype.args]
            return "{}[{}]".format(alias, ", ".join(items))
        else:
            # There are type arguments. Convert the arguments to strings.
            # If the result is too long, replace arguments with [...].
            a = []  # type: List[str]
            for arg in itype.args:
                a.append(self.format_bare(arg))
            s = ", ".join(a)
            if len((base_str + s)) < 150:
                return "{}[{}]".format(base_str, s)
            else:
                return "{}[...]".format(base_str)
    elif isinstance(typ, TypeVarType):
        # This is similar to non-generic instance types.
        return typ.name
    elif isinstance(typ, TupleType):
        # Prefer the name of the fallback class (if not tuple), as it's more informative.
        if typ.fallback.type.fullname() != "builtins.tuple":
            return self.format_bare(typ.fallback)
        items = []
        for t in typ.items:
            items.append(self.format_bare(t))
        s = "Tuple[{}]".format(", ".join(items))
        if len(s) < 400:
            return s
        else:
            return "<tuple: {} items>".format(len(items))
    elif isinstance(typ, TypedDictType):
        # If the TypedDictType is named, return the name
        if not typ.is_anonymous():
            return self.format_bare(typ.fallback)
        items = []
        for item_name, item_type in typ.items.items():
            modifier = "" if item_name in typ.required_keys else "?"
            items.append(
                "{!r}{}: {}".format(item_name, modifier, self.format_bare(item_type))
            )
        s = "TypedDict({{{}}})".format(", ".join(items))
        return s
    elif isinstance(typ, UnionType):
        # Only print Unions as Optionals if the Optional wouldn't have to contain another Union
        print_as_optional = (
            len(typ.items) - sum(isinstance(t, NoneTyp) for t in typ.items) == 1
        )
        if print_as_optional:
            rest = [t for t in typ.items if not isinstance(t, NoneTyp)]
            return "Optional[{}]".format(self.format_bare(rest[0]))
        else:
            items = []
            for t in typ.items:
                items.append(self.format_bare(t))
            s = "Union[{}]".format(", ".join(items))
            if len(s) < 400:
                return s
            else:
                return "<union: {} items>".format(len(items))
    elif isinstance(typ, NoneTyp):
        return "None"
    elif isinstance(typ, AnyType):
        return "Any"
    elif isinstance(typ, DeletedType):
        return "<deleted>"
    elif isinstance(typ, UninhabitedType):
        if typ.is_noreturn:
            return "NoReturn"
        else:
            return "<nothing>"
    elif isinstance(typ, TypeType):
        return "Type[{}]".format(self.format_bare(typ.item, verbosity))
    elif isinstance(typ, FunctionLike):
        func = typ
        if func.is_type_obj():
            # The type of a type object type can be derived from the
            # return type (this always works).
            return self.format_bare(
                TypeType.make_normalized(erase_type(func.items()[0].ret_type)),
                verbosity,
            )
        elif isinstance(func, CallableType):
            return_type = self.format_bare(func.ret_type)
            if func.is_ellipsis_args:
                return "Callable[..., {}]".format(return_type)
            arg_strings = []
            for arg_name, arg_type, arg_kind in zip(
                func.arg_names, func.arg_types, func.arg_kinds
            ):
                if (
                    arg_kind == ARG_POS
                    and arg_name is None
                    or verbosity == 0
                    and arg_kind in (ARG_POS, ARG_OPT)
                ):
                    arg_strings.append(
                        self.format_bare(arg_type, verbosity=max(verbosity - 1, 0))
                    )
                else:
                    constructor = ARG_CONSTRUCTOR_NAMES[arg_kind]
                    if arg_kind in (ARG_STAR, ARG_STAR2) or arg_name is None:
                        arg_strings.append(
                            "{}({})".format(constructor, self.format_bare(arg_type))
                        )
                    else:
                        arg_strings.append(
                            "{}({}, {})".format(
                                constructor, self.format_bare(arg_type), repr(arg_name)
                            )
                        )

            return "Callable[[{}], {}]".format(", ".join(arg_strings), return_type)
        else:
            # Use a simple representation for function types; proper
            # function types may result in long and difficult-to-read
            # error messages.
            return "overloaded function"
    elif typ is None:
        raise RuntimeError("Type is None")
    else:
        # Default case; we simply have to return something meaningful here.
        return "object"


# Traceback (TypeError)
mypy --show-traceback Deduction.py
Deduction.py:102: error: The return type of "__init__" must be None
Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty
Traceback (most recent call last):
File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module>
load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')()
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry
main(None)
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main
res = type_check_only(sources, bin_dir, options)
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only
options=options)
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build
graph = dispatch(sources, manager)
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch
process_graph(graph, manager)
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph
process_stale_scc(graph, scc, manager)
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc
graph[id].type_check_first_pass()
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass
self.type_checker.check_first_pass()
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass
self.accept(d)
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept
stmt.accept(self)
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept
return visitor.visit_class_def(self)
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def
self.accept(defn.defs)
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept
stmt.accept(self)
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept
return visitor.visit_block(self)
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block
self.accept(s)
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept
stmt.accept(self)
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept
return visitor.visit_func_def(self)
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def
self.check_func_item(defn, name=defn.name())
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item
self.check_func_def(defn, typ, name)
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def
self.accept(item.body)
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept
stmt.accept(self)
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept
return visitor.visit_block(self)
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block
self.accept(s)
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept
stmt.accept(self)
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept
return visitor.visit_if_stmt(self)
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt
if_map, else_map = self.find_isinstance_check(e)
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check
return find_isinstance_check(n, self.type_map)
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check
return conditional_type_map(expr, vartype, type)
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map
and is_proper_subtype(current_type, proposed_type)):
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype
return left.accept(ProperSubtypeVisitor(right))
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept
return visitor.visit_union_type(self)
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type
return all([is_proper_subtype(item, self.right) for item in left.items])
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp>
return all([is_proper_subtype(item, self.right) for item in left.items])
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype
return left.accept(ProperSubtypeVisitor(right))
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept
return visitor.visit_tuple_type(self)
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type
if not is_proper_subtype(l, r):
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype
return left.accept(ProperSubtypeVisitor(right))
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept
return visitor.visit_instance(self)
File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance
for base in left.type.mro:
TypeError: 'NoneType' object is not iterable
Deduction.py:103: note: use --pdb to drop into pdb

# Fixed code
def format_bare(self, typ: Type, verbosity: int = 0) -> str:
    """
    Convert a type to a relatively short string suitable for error messages.

    This method will return an unquoted string.  If a caller doesn't need to
    perform post-processing on the string output, .format should be used
    instead.  (The caller may want to use .quote_type_string after
    processing has happened, to maintain consistent quoting in messages.)
    """
    if isinstance(typ, Instance):
        itype = typ
        # Get the short name of the type.
        if itype.type.fullname() in (
            "types.ModuleType",
            "_importlib_modulespec.ModuleType",
        ):
            # Make some common error messages simpler and tidier.
            return "Module"
        if verbosity >= 2:
            base_str = itype.type.fullname()
        else:
            base_str = itype.type.name()
        if itype.args == []:
            # No type arguments, just return the type name
            return base_str
        elif itype.type.fullname() == "builtins.tuple":
            item_type_str = self.format_bare(itype.args[0])
            return "Tuple[{}, ...]".format(item_type_str)
        elif itype.type.fullname() in reverse_type_aliases:
            alias = reverse_type_aliases[itype.type.fullname()]
            alias = alias.split(".")[-1]
            items = [self.format_bare(arg) for arg in itype.args]
            return "{}[{}]".format(alias, ", ".join(items))
        else:
            # There are type arguments. Convert the arguments to strings.
            # If the result is too long, replace arguments with [...].
            a = []  # type: List[str]
            for arg in itype.args:
                a.append(self.format_bare(arg))
            s = ", ".join(a)
            if len((base_str + s)) < 150:
                return "{}[{}]".format(base_str, s)
            else:
                return "{}[...]".format(base_str)
    elif isinstance(typ, TypeVarType):
        # This is similar to non-generic instance types.
        return typ.name
    elif isinstance(typ, TupleType):
        # Prefer the name of the fallback class (if not tuple), as it's more informative.
        if typ.fallback.type.fullname() != "builtins.tuple":
            return self.format_bare(typ.fallback)
        items = []
        for t in typ.items:
            items.append(self.format_bare(t))
        s = "Tuple[{}]".format(", ".join(items))
        if len(s) < 400:
            return s
        else:
            return "<tuple: {} items>".format(len(items))
    elif isinstance(typ, TypedDictType):
        # If the TypedDictType is named, return the name
        if not typ.is_anonymous():
            return self.format_bare(typ.fallback)
        items = []
        for item_name, item_type in typ.items.items():
            modifier = "" if item_name in typ.required_keys else "?"
            items.append(
                "{!r}{}: {}".format(item_name, modifier, self.format_bare(item_type))
            )
        s = "TypedDict({{{}}})".format(", ".join(items))
        return s
    elif isinstance(typ, UnionType):
        # Only print Unions as Optionals if the Optional wouldn't have to contain another Union
        print_as_optional = (
            len(typ.items) - sum(isinstance(t, NoneTyp) for t in typ.items) == 1
        )
        if print_as_optional:
            rest = [t for t in typ.items if not isinstance(t, NoneTyp)]
            return "Optional[{}]".format(self.format_bare(rest[0]))
        else:
            items = []
            for t in typ.items:
                items.append(self.format_bare(t))
            s = "Union[{}]".format(", ".join(items))
            if len(s) < 400:
                return s
            else:
                return "<union: {} items>".format(len(items))
    elif isinstance(typ, NoneTyp):
        return "None"
    elif isinstance(typ, AnyType):
        return "Any"
    elif isinstance(typ, DeletedType):
        return "<deleted>"
    elif isinstance(typ, UninhabitedType):
        if typ.is_noreturn:
            return "NoReturn"
        else:
            return "<nothing>"
    elif isinstance(typ, TypeType):
        return "Type[{}]".format(self.format_bare(typ.item, verbosity))
    elif isinstance(typ, ForwardRef):  # may appear in semanal.py
        return self.format_bare(typ.link, verbosity)
    elif isinstance(typ, FunctionLike):
        func = typ
        if func.is_type_obj():
            # The type of a type object type can be derived from the
            # return type (this always works).
            return self.format_bare(
                TypeType.make_normalized(erase_type(func.items()[0].ret_type)),
                verbosity,
            )
        elif isinstance(func, CallableType):
            return_type = self.format_bare(func.ret_type)
            if func.is_ellipsis_args:
                return "Callable[..., {}]".format(return_type)
            arg_strings = []
            for arg_name, arg_type, arg_kind in zip(
                func.arg_names, func.arg_types, func.arg_kinds
            ):
                if (
                    arg_kind == ARG_POS
                    and arg_name is None
                    or verbosity == 0
                    and arg_kind in (ARG_POS, ARG_OPT)
                ):
                    arg_strings.append(
                        self.format_bare(arg_type, verbosity=max(verbosity - 1, 0))
                    )
                else:
                    constructor = ARG_CONSTRUCTOR_NAMES[arg_kind]
                    if arg_kind in (ARG_STAR, ARG_STAR2) or arg_name is None:
                        arg_strings.append(
                            "{}({})".format(constructor, self.format_bare(arg_type))
                        )
                    else:
                        arg_strings.append(
                            "{}({}, {})".format(
                                constructor, self.format_bare(arg_type), repr(arg_name)
                            )
                        )

            return "Callable[[{}], {}]".format(", ".join(arg_strings), return_type)
        else:
            # Use a simple representation for function types; proper
            # function types may result in long and difficult-to-read
            # error messages.
            return "overloaded function"
    elif isinstance(typ, UnboundType):
        return str(typ)
    elif typ is None:
        raise RuntimeError("Type is None")
    else:
        # Default case; we simply have to return something meaningful here.
        return "object"