[ty] Remove duplicate invalid-type-form diagnostics for PEP-613 type alias values by AlexWaygood · Pull Request #24760 · astral-sh/ruff (original) (raw)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I experimented with using an FxIndexSet for TypeCheckDiagnostics::diagnostics locally, to deuplicate all diagnostics, rather than simply adding some special casing for invalid-type-form and other diagnostics that are only emitted from type_expression.rs. However, just switching the internal data structure to a set doesn't fix this case: we still emit two (presumably very slightly different) diagnostics on this line if that's the only change made. So we would still need to track the context more precisely even if we did that, in order to fix this case.

Ensuring that diagnostics are always deduplicated also had an impact on a number of other diagnostics in our test suite. Several of these had TODOs next to them saying that ideally we would only emit one diagnostic, but in some cases emitting multiple diagnostics really does seem to be the "correct" thing to do (even if they'd ideally not be identical -- I worry that using a set to store diagnostics would paper over these cases.