# Buggy code
def analyze_base_classes(self, defn: ClassDef) -> None:
    """Analyze and set up base classes.

    This computes several attributes on the corresponding TypeInfo defn.info
    related to the base classes: defn.info.bases, defn.info.mro, and
    miscellaneous others (at least tuple_type, fallback_to_any, and is_enum.)
    """

    base_types = []  # type: List[Instance]
    info = defn.info

    for base_expr in defn.base_type_exprs:
        try:
            base = self.expr_to_analyzed_type(base_expr)
        except TypeTranslationError:
            self.fail("Invalid base class", base_expr)
            info.fallback_to_any = True
            continue

        if isinstance(base, TupleType):
            if info.tuple_type:
                self.fail("Class has two incompatible bases derived from tuple", defn)
                defn.has_incompatible_baseclass = True
            info.tuple_type = base
            base_types.append(base.fallback)
        elif isinstance(base, Instance):
            if base.type.is_newtype:
                self.fail("Cannot subclass NewType", defn)
            base_types.append(base)
        elif isinstance(base, AnyType):
            if self.options.disallow_subclassing_any:
                if isinstance(base_expr, (NameExpr, MemberExpr)):
                    msg = "Class cannot subclass '{}' (has type 'Any')".format(
                        base_expr.name
                    )
                else:
                    msg = "Class cannot subclass value of type 'Any'"
                self.fail(msg, base_expr)
            info.fallback_to_any = True
        else:
            self.fail("Invalid base class", base_expr)
            info.fallback_to_any = True
        if "unimported" in self.options.disallow_any and has_any_from_unimported_type(
            base
        ):
            if isinstance(base_expr, (NameExpr, MemberExpr)):
                prefix = "Base type {}".format(base_expr.name)
            else:
                prefix = "Base type"
            self.msg.unimported_type_becomes_any(prefix, base, base_expr)
        check_for_explicit_any(
            base, self.options, self.is_typeshed_stub_file, self.msg, context=base_expr
        )

    # Add 'object' as implicit base if there is no other base class.
    if not base_types and defn.fullname != "builtins.object":
        base_types.append(self.object_type())

    info.bases = base_types

    # Calculate the MRO. It might be incomplete at this point if
    # the bases of defn include classes imported from other
    # modules in an import loop. We'll recompute it in ThirdPass.
    if not self.verify_base_classes(defn):
        # Give it an MRO consisting of just the class itself and object.
        defn.info.mro = [defn.info, self.object_type().type]
        return
    calculate_class_mro(defn, self.fail_blocker)
    # If there are cyclic imports, we may be missing 'object' in
    # the MRO. Fix MRO if needed.
    if info.mro and info.mro[-1].fullname() != "builtins.object":
        info.mro.append(self.object_type().type)
    if defn.info.is_enum and defn.type_vars:
        self.fail("Enum class cannot be generic", defn)


# 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 analyze_base_classes(self, defn: ClassDef) -> None:
    """Analyze and set up base classes.

    This computes several attributes on the corresponding TypeInfo defn.info
    related to the base classes: defn.info.bases, defn.info.mro, and
    miscellaneous others (at least tuple_type, fallback_to_any, and is_enum.)
    """

    base_types = []  # type: List[Instance]
    info = defn.info

    for base_expr in defn.base_type_exprs:
        try:
            base = self.expr_to_analyzed_type(base_expr)
        except TypeTranslationError:
            self.fail("Invalid base class", base_expr)
            info.fallback_to_any = True
            continue

        if isinstance(base, TupleType):
            if info.tuple_type:
                self.fail("Class has two incompatible bases derived from tuple", defn)
                defn.has_incompatible_baseclass = True
            info.tuple_type = base
            base_types.append(base.fallback)
            if isinstance(base_expr, CallExpr):
                defn.analyzed = NamedTupleExpr(base.fallback.type)
                defn.analyzed.line = defn.line
                defn.analyzed.column = defn.column
        elif isinstance(base, Instance):
            if base.type.is_newtype:
                self.fail("Cannot subclass NewType", defn)
            base_types.append(base)
        elif isinstance(base, AnyType):
            if self.options.disallow_subclassing_any:
                if isinstance(base_expr, (NameExpr, MemberExpr)):
                    msg = "Class cannot subclass '{}' (has type 'Any')".format(
                        base_expr.name
                    )
                else:
                    msg = "Class cannot subclass value of type 'Any'"
                self.fail(msg, base_expr)
            info.fallback_to_any = True
        else:
            self.fail("Invalid base class", base_expr)
            info.fallback_to_any = True
        if "unimported" in self.options.disallow_any and has_any_from_unimported_type(
            base
        ):
            if isinstance(base_expr, (NameExpr, MemberExpr)):
                prefix = "Base type {}".format(base_expr.name)
            else:
                prefix = "Base type"
            self.msg.unimported_type_becomes_any(prefix, base, base_expr)
        check_for_explicit_any(
            base, self.options, self.is_typeshed_stub_file, self.msg, context=base_expr
        )

    # Add 'object' as implicit base if there is no other base class.
    if not base_types and defn.fullname != "builtins.object":
        base_types.append(self.object_type())

    info.bases = base_types

    # Calculate the MRO. It might be incomplete at this point if
    # the bases of defn include classes imported from other
    # modules in an import loop. We'll recompute it in ThirdPass.
    if not self.verify_base_classes(defn):
        # Give it an MRO consisting of just the class itself and object.
        defn.info.mro = [defn.info, self.object_type().type]
        return
    calculate_class_mro(defn, self.fail_blocker)
    # If there are cyclic imports, we may be missing 'object' in
    # the MRO. Fix MRO if needed.
    if info.mro and info.mro[-1].fullname() != "builtins.object":
        info.mro.append(self.object_type().type)
    if defn.info.is_enum and defn.type_vars:
        self.fail("Enum class cannot be generic", defn)