[`pyflakes`] Fix infinite loop with unused local import in `__init__.py` (`F401`) (#15517)
## Summary
This fixes the infinite loop reported in #12897, where an
`unused-import` that is undefined at the scope of `__all__` is "fixed"
by adding it to `__all__` repeatedly. These changes make it so that only
imports in the global scope will be suggested to add to `__all__` and
the unused local import is simply removed.
## Test Plan
Added a CLI integration test that sets up the same module structure as
the original report
Closes #12897
---------
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>