# Buggy code
def visit_instance(self, t: Instance, from_fallback: bool = False) -> Type:
    """This visitor method tracks situations like this:

           x: A  # When analyzing this type we will get an Instance from SemanticAnalyzerPass1.
                 # Now we need to update this to actual analyzed TupleType.
           class A(NamedTuple):
               attr: str

    If from_fallback is True, then we always return an Instance type. This is needed
    since TupleType and TypedDictType fallbacks are always instances.
    """
    info = t.type
    # Special case, analyzed bases transformed the type into TupleType.
    if info.tuple_type and not from_fallback:
        items = [it.accept(self) for it in info.tuple_type.items]
        info.tuple_type.items = items
        return TupleType(items, Instance(info, []))
    # Update forward Instances to corresponding analyzed NamedTuples.
    if info.replaced and info.replaced.tuple_type:
        tp = info.replaced.tuple_type
        if self.check_recursion(tp):
            # The key idea is that when we recursively return to a type already traversed,
            # then we break the cycle and put AnyType as a leaf.
            return AnyType(TypeOfAny.from_error)
        return tp.copy_modified(fallback=Instance(info.replaced, [])).accept(self)
    # Same as above but for TypedDicts.
    if info.replaced and info.replaced.typeddict_type:
        td = info.replaced.typeddict_type
        if self.check_recursion(td):
            # We also break the cycles for TypedDicts as explained above for NamedTuples.
            return AnyType(TypeOfAny.from_error)
        return td.copy_modified(fallback=Instance(info.replaced, [])).accept(self)
    if self.check_recursion(t):
        # We also need to break a potential cycle with normal (non-synthetic) instance types.
        return Instance(
            t.type, [AnyType(TypeOfAny.from_error)] * len(t.type.defn.type_vars)
        )
    return super().visit_instance(t)


# Traceback (TypeError)
typetest.py:5: error: Recursive types not fully supported yet, nested types replaced with "Any"
typetest.py: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.610
Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/jo/.local/lib/python3.6/site-packages/mypy/__main__.py", line 11, in <module>
main(None)
File "/home/jo/.local/lib/python3.6/site-packages/mypy/main.py", line 91, in main
res = type_check_only(sources, bin_dir, options, flush_errors, fscache)  # noqa
File "/home/jo/.local/lib/python3.6/site-packages/mypy/main.py", line 148, in type_check_only
fscache=fscache)
File "/home/jo/.local/lib/python3.6/site-packages/mypy/build.py", line 185, in build
flush_errors, fscache)
File "/home/jo/.local/lib/python3.6/site-packages/mypy/build.py", line 285, in _build
graph = dispatch(sources, manager)
File "/home/jo/.local/lib/python3.6/site-packages/mypy/build.py", line 2398, in dispatch
process_graph(graph, manager)
File "/home/jo/.local/lib/python3.6/site-packages/mypy/build.py", line 2691, in process_graph
process_stale_scc(graph, scc, manager)
File "/home/jo/.local/lib/python3.6/site-packages/mypy/build.py", line 2820, in process_stale_scc
graph[id].finish_passes()
File "/home/jo/.local/lib/python3.6/site-packages/mypy/build.py", line 2067, in finish_passes
manager.report_file(self.tree, self.type_map(), self.options)
File "/usr/lib/python3.6/contextlib.py", line 99, in __exit__
self.gen.throw(type, value, traceback)
File "/home/jo/.local/lib/python3.6/site-packages/mypy/build.py", line 1818, in wrap_context
yield
File "/home/jo/.local/lib/python3.6/site-packages/mypy/build.py", line 2062, in finish_passes
self._patch_indirect_dependencies(self.type_checker().module_refs, self.type_map())
File "/home/jo/.local/lib/python3.6/site-packages/mypy/build.py", line 2076, in _patch_indirect_dependencies
encountered = self.manager.indirection_detector.find_modules(types) | module_refs
File "/home/jo/.local/lib/python3.6/site-packages/mypy/indirection.py", line 29, in find_modules
return self._visit(*typs)
File "/home/jo/.local/lib/python3.6/site-packages/mypy/indirection.py", line 37, in _visit
modules = typ.accept(self)
File "/home/jo/.local/lib/python3.6/site-packages/mypy/types.py", line 1042, in accept
return visitor.visit_tuple_type(self)
File "/home/jo/.local/lib/python3.6/site-packages/mypy/indirection.py", line 91, in visit_tuple_type
return self._visit(*t.items) | self._visit(t.fallback)
File "/home/jo/.local/lib/python3.6/site-packages/mypy/indirection.py", line 37, in _visit
modules = typ.accept(self)
File "/home/jo/.local/lib/python3.6/site-packages/mypy/types.py", line 512, in accept
return visitor.visit_instance(self)
File "/home/jo/.local/lib/python3.6/site-packages/mypy/indirection.py", line 70, in visit_instance
out = self._visit(*t.args)
File "/home/jo/.local/lib/python3.6/site-packages/mypy/indirection.py", line 37, in _visit
modules = typ.accept(self)
File "/home/jo/.local/lib/python3.6/site-packages/mypy/types.py", line 512, in accept
return visitor.visit_instance(self)
File "/home/jo/.local/lib/python3.6/site-packages/mypy/indirection.py", line 75, in visit_instance
for s in t.type.mro:
TypeError: 'NoneType' object is not iterable
typetest.py: : note: use --pdb to drop into pdb

# Fixed code
def visit_instance(self, t: Instance, from_fallback: bool = False) -> Type:
    """This visitor method tracks situations like this:

           x: A  # When analyzing this type we will get an Instance from SemanticAnalyzerPass1.
                 # Now we need to update this to actual analyzed TupleType.
           class A(NamedTuple):
               attr: str

    If from_fallback is True, then we always return an Instance type. This is needed
    since TupleType and TypedDictType fallbacks are always instances.
    """
    info = t.type
    # Special case, analyzed bases transformed the type into TupleType.
    if info.tuple_type and not from_fallback:
        items = [it.accept(self) for it in info.tuple_type.items]
        info.tuple_type.items = items
        return TupleType(items, Instance(info, []))
    # Update forward Instances to corresponding analyzed NamedTuples.
    if info.replaced and info.replaced.tuple_type:
        tp = info.replaced.tuple_type
        if self.check_recursion(tp):
            # The key idea is that when we recursively return to a type already traversed,
            # then we break the cycle and put AnyType as a leaf.
            return AnyType(TypeOfAny.from_error)
        return tp.copy_modified(
            fallback=Instance(info.replaced, [], line=t.line)
        ).accept(self)
    # Same as above but for TypedDicts.
    if info.replaced and info.replaced.typeddict_type:
        td = info.replaced.typeddict_type
        if self.check_recursion(td):
            # We also break the cycles for TypedDicts as explained above for NamedTuples.
            return AnyType(TypeOfAny.from_error)
        return td.copy_modified(
            fallback=Instance(info.replaced, [], line=t.line)
        ).accept(self)
    if self.check_recursion(t):
        # We also need to break a potential cycle with normal (non-synthetic) instance types.
        return Instance(
            t.type,
            [AnyType(TypeOfAny.from_error)] * len(t.type.defn.type_vars),
            line=t.line,
        )
    return super().visit_instance(t)