Don't infinite loop on self deps in --follow-imports=normal (#9302)
There are situations in complex SCCs where the semantic analyzer will
infer self dependencies, which will cause an infinite loop in `dmypy
--follow-imports=normal`.
It's probably a bug that we do that, and that should be fixed to, but
fixing a graph algorithm to not infinite loop on self edges seems like
a reasonable thing to do in any case.
I don't have a minimized test case yet, and am submitting this without
one because it should be harmless and because I want it to get into
the release.