AssertionError in deeply nested class scenario (incremental with warm cache)

This is a small remainder of #2535

Example to reproduce: run mypy -i main.py twice (without touching any files in between) where:

  • main.py
import ntcrash
  • ntcrash.py
from typing import NamedTuple

class C:
    def f(self) -> None:
        class D:
            class E:
                def g(self) -> None:
                    A = NamedTuple('A', [('x', int), ('y', int)])
                    self.a = A(1, 1)
        self.c = D.E().a

Possible fix would be to store all "anonymous" classes in globals.