# Buggy code
def visit_assignment_stmt(self, s: AssignmentStmt) -> None:
    """Traverse the assignment statement.

    This includes the actual assignment and synthetic types
    resulted from this assignment (if any). Currently this includes
    NewType, TypedDict, NamedTuple, and TypeVar.
    """
    self.analyze(s.type, s)
    if isinstance(s.rvalue, IndexExpr) and isinstance(s.rvalue.analyzed, TypeAliasExpr):
        self.analyze(s.rvalue.analyzed.type, s.rvalue.analyzed, warn=True)
    if isinstance(s.rvalue, CallExpr):
        analyzed = s.rvalue.analyzed
        if isinstance(analyzed, NewTypeExpr):
            self.analyze(analyzed.old_type, analyzed)
            if analyzed.info and analyzed.info.mro:
                analyzed.info.mro = []  # Force recomputation
                mypy.semanal.calculate_class_mro(analyzed.info.defn, self.fail_blocker)
        if isinstance(analyzed, TypeVarExpr):
            types = []
            if analyzed.upper_bound:
                types.append(analyzed.upper_bound)
            if analyzed.values:
                types.extend(analyzed.values)
            self.analyze_types(types, analyzed)
        if isinstance(analyzed, TypedDictExpr):
            self.analyze(analyzed.info.typeddict_type, analyzed, warn=True)
        if isinstance(analyzed, NamedTupleExpr):
            self.analyze(analyzed.info.tuple_type, analyzed, warn=True)
            for name in analyzed.info.names:
                sym = analyzed.info.names[name]
                if isinstance(sym.node, (FuncDef, Decorator)):
                    self.accept(sym.node)
                if isinstance(sym.node, Var):
                    self.analyze(sym.node.type, sym.node)
    # We need to pay additional attention to assignments that define a type alias.
    # The resulting type is also stored in the 'type_override' attribute of
    # the corresponding SymbolTableNode.
    if isinstance(s.lvalues[0], RefExpr) and isinstance(s.lvalues[0].node, Var):
        self.analyze(s.lvalues[0].node.type, s.lvalues[0].node)
        if isinstance(s.lvalues[0], NameExpr):
            node = self.sem.lookup(s.lvalues[0].name, s, suppress_errors=True)
            if node:
                self.analyze(node.type_override, node)
    super().visit_assignment_stmt(s)


# Traceback (AssertionError)
Traceback (most recent call last):
File "/Users/daenyth/Curata/cmp/.tox/mypy/bin/mypy", line 11, in <module>
sys.exit(console_entry())
File "/Users/daenyth/Curata/cmp/.tox/mypy/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry
main(None)
File "/Users/daenyth/Curata/cmp/.tox/mypy/lib/python3.6/site-packages/mypy/main.py", line 50, in main
res = type_check_only(sources, bin_dir, options)
File "/Users/daenyth/Curata/cmp/.tox/mypy/lib/python3.6/site-packages/mypy/main.py", line 103, in type_check_only
options=options)
File "/Users/daenyth/Curata/cmp/.tox/mypy/lib/python3.6/site-packages/mypy/build.py", line 198, in build
graph = dispatch(sources, manager)
File "/Users/daenyth/Curata/cmp/.tox/mypy/lib/python3.6/site-packages/mypy/build.py", line 1841, in dispatch
process_graph(graph, manager)
File "/Users/daenyth/Curata/cmp/.tox/mypy/lib/python3.6/site-packages/mypy/build.py", line 2091, in process_graph
process_stale_scc(graph, scc, manager)
File "/Users/daenyth/Curata/cmp/.tox/mypy/lib/python3.6/site-packages/mypy/build.py", line 2203, in process_stale_scc
graph[id].write_cache()
File "/Users/daenyth/Curata/cmp/.tox/mypy/lib/python3.6/site-packages/mypy/build.py", line 1822, in write_cache
self.manager)
File "/Users/daenyth/Curata/cmp/.tox/mypy/lib/python3.6/site-packages/mypy/build.py", line 1088, in write_cache
data = tree.serialize()
File "/Users/daenyth/Curata/cmp/.tox/mypy/lib/python3.6/site-packages/mypy/nodes.py", line 238, in serialize
'names': self.names.serialize(self._fullname),
File "/Users/daenyth/Curata/cmp/.tox/mypy/lib/python3.6/site-packages/mypy/nodes.py", line 2432, in serialize
data[key] = value.serialize(fullname, key)
File "/Users/daenyth/Curata/cmp/.tox/mypy/lib/python3.6/site-packages/mypy/nodes.py", line 2371, in serialize
data['node'] = self.node.serialize()
File "/Users/daenyth/Curata/cmp/.tox/mypy/lib/python3.6/site-packages/mypy/nodes.py", line 2194, in serialize
'names': self.names.serialize(self.fullname()),
File "/Users/daenyth/Curata/cmp/.tox/mypy/lib/python3.6/site-packages/mypy/nodes.py", line 2432, in serialize
data[key] = value.serialize(fullname, key)
File "/Users/daenyth/Curata/cmp/.tox/mypy/lib/python3.6/site-packages/mypy/nodes.py", line 2371, in serialize
data['node'] = self.node.serialize()
File "/Users/daenyth/Curata/cmp/.tox/mypy/lib/python3.6/site-packages/mypy/nodes.py", line 533, in serialize
'type': None if self.type is None else self.type.serialize(),
File "/Users/daenyth/Curata/cmp/.tox/mypy/lib/python3.6/site-packages/mypy/types.py", line 857, in serialize
'arg_types': [t.serialize() for t in self.arg_types],
File "/Users/daenyth/Curata/cmp/.tox/mypy/lib/python3.6/site-packages/mypy/types.py", line 857, in <listcomp>
'arg_types': [t.serialize() for t in self.arg_types],
File "/Users/daenyth/Curata/cmp/.tox/mypy/lib/python3.6/site-packages/mypy/types.py", line 496, in serialize
data['args'] = [arg.serialize() for arg in self.args]
File "/Users/daenyth/Curata/cmp/.tox/mypy/lib/python3.6/site-packages/mypy/types.py", line 496, in <listcomp>
data['args'] = [arg.serialize() for arg in self.args]
File "/Users/daenyth/Curata/cmp/.tox/mypy/lib/python3.6/site-packages/mypy/types.py", line 994, in serialize
'items': [t.serialize() for t in self.items],
File "/Users/daenyth/Curata/cmp/.tox/mypy/lib/python3.6/site-packages/mypy/types.py", line 994, in <listcomp>
'items': [t.serialize() for t in self.items],
File "/Users/daenyth/Curata/cmp/.tox/mypy/lib/python3.6/site-packages/mypy/types.py", line 1410, in serialize
assert False, "Internal error: Unresolved forward reference to {}".format(name)
AssertionError: Internal error: Unresolved forward reference to UnboundType

# Fixed code
def visit_assignment_stmt(self, s: AssignmentStmt) -> None:
    """Traverse the assignment statement.

    This includes the actual assignment and synthetic types
    resulted from this assignment (if any). Currently this includes
    NewType, TypedDict, NamedTuple, and TypeVar.
    """
    self.analyze(s.type, s)
    if isinstance(s.rvalue, IndexExpr) and isinstance(s.rvalue.analyzed, TypeAliasExpr):
        self.analyze(s.rvalue.analyzed.type, s.rvalue.analyzed, warn=True)
    if isinstance(s.rvalue, CallExpr):
        analyzed = s.rvalue.analyzed
        if isinstance(analyzed, NewTypeExpr):
            self.analyze(analyzed.old_type, analyzed)
            if analyzed.info:
                # Currently NewTypes only have __init__, but to be future proof,
                # we analyze all symbols.
                self.analyze_info(analyzed.info)
            if analyzed.info and analyzed.info.mro:
                analyzed.info.mro = []  # Force recomputation
                mypy.semanal.calculate_class_mro(analyzed.info.defn, self.fail_blocker)
        if isinstance(analyzed, TypeVarExpr):
            types = []
            if analyzed.upper_bound:
                types.append(analyzed.upper_bound)
            if analyzed.values:
                types.extend(analyzed.values)
            self.analyze_types(types, analyzed)
        if isinstance(analyzed, TypedDictExpr):
            self.analyze(analyzed.info.typeddict_type, analyzed, warn=True)
        if isinstance(analyzed, NamedTupleExpr):
            self.analyze(analyzed.info.tuple_type, analyzed, warn=True)
            self.analyze_info(analyzed.info)
    # We need to pay additional attention to assignments that define a type alias.
    # The resulting type is also stored in the 'type_override' attribute of
    # the corresponding SymbolTableNode.
    if isinstance(s.lvalues[0], RefExpr) and isinstance(s.lvalues[0].node, Var):
        self.analyze(s.lvalues[0].node.type, s.lvalues[0].node)
        if isinstance(s.lvalues[0], NameExpr):
            node = self.sem.lookup(s.lvalues[0].name, s, suppress_errors=True)
            if node:
                self.analyze(node.type_override, node)
    super().visit_assignment_stmt(s)