[ty] Fix panic for cyclic star imports by MichaReiser · Pull Request #21428 · astral-sh/ruff (original) (raw)

Summary

Fixes astral-sh/ty#444

This PR fixes a panic where the export_names query never converged for a cyclic star import.

This is a rather silly bug. The cycle never converged because the symbol ordering changed between iterations (forever)....

Here's a diff between the exported symbols before the fix for the last two iterations

https://www.diffchecker.com/tk3ihAdo/

This PR fixes the bug by simply sorting the names before returning.

I considered using a BTreeMap but found the sort slightly simpler (and both roughly have the same complexity)

Test Plan

I recreated the MRE from the linked issue and verified that it panics without my changes.