Skip to content

Comments

[ty] Improve UX for [duplicate-base] diagnostics#17914

Merged
AlexWaygood merged 3 commits intomainfrom
alex/dup-bases-diagnostic
May 7, 2025
Merged

[ty] Improve UX for [duplicate-base] diagnostics#17914
AlexWaygood merged 3 commits intomainfrom
alex/dup-bases-diagnostic

Conversation

@AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented May 7, 2025

Summary

This PR improves the UX of our duplicate-base diagnostics so that we:

  • Say explicitly what's wrong with including a duplicate base (it's going to raise TypeError at runtime)
  • Highlight the original occurence of the base in the bases list as well as its second occurence
  • If a base is duplicated multiple times, only report a single diagnostic for all occurences rather than multiple diagnostics
Screenshot of what the new diagnostics look like in the terminal

image

Test Plan

Snapshots added

@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label May 7, 2025
@github-actions
Copy link
Contributor

github-actions bot commented May 7, 2025

mypy_primer results

No ecosystem changes detected ✅

@MichaReiser
Copy link
Member

Nice.

I think this does have the downside that it's now only possible to suppress the error at the first or last line of the class declaration but not where the base class is repeated (because suppressions use the primary range).

Have you considered changing the primary range to the arguments range instead of the entire class header?

@AlexWaygood AlexWaygood force-pushed the alex/dup-bases-diagnostic branch from 70d6aad to 8351343 Compare May 7, 2025 12:53
@AlexWaygood
Copy link
Member Author

I think this does have the downside that it's now only possible to suppress the error at the first or last line of the class declaration but not where the base class is repeated (because suppressions use the primary range).

Yeah. I think this is justifiable, though, given that it's the class definition as a whole that will fail and raise an exception at runtime, not any of the sub-expressions inside the argument list.

Have you considered changing the primary range to the arguments range instead of the entire class header?

I could do that, but again, it's the class definition as a whole that will fail; the name of the class feels like relevant information that's useful to have highlighted

@AlexWaygood AlexWaygood force-pushed the alex/dup-bases-diagnostic branch 2 times, most recently from 84d8df2 to 291f4d0 Compare May 7, 2025 13:44
@AlexWaygood AlexWaygood force-pushed the alex/dup-bases-diagnostic branch from 291f4d0 to 1ec9b0e Compare May 7, 2025 13:44
@AlexWaygood AlexWaygood requested a review from MichaReiser May 7, 2025 13:46
@AlexWaygood AlexWaygood force-pushed the alex/dup-bases-diagnostic branch from 51bbfcd to e99571b Compare May 7, 2025 15:24
@AlexWaygood AlexWaygood enabled auto-merge (squash) May 7, 2025 15:27
@AlexWaygood AlexWaygood merged commit 2ec0d7e into main May 7, 2025
34 checks passed
@AlexWaygood AlexWaygood deleted the alex/dup-bases-diagnostic branch May 7, 2025 15:27
dcreager added a commit that referenced this pull request May 7, 2025
…lass

* origin/main:
  [`pylint`] add fix safety section (`PLC2801`) (#17825)
  Add instructions on how to upgrade to a newer Rust version (#17928)
  [parser] Flag single unparenthesized generator expr with trailing comma in arguments. (#17893)
  [ty] Ensure that `T` is disjoint from `~T` even when `T` is a TypeVar (#17922)
  [ty] Sort collected diagnostics before snapshotting them in mdtest (#17926)
  [ty] Add basic file watching to server (#17912)
  Make completions an opt-in LSP feature (#17921)
  Add link to `ty` issue tracker (#17924)
  [ty] Add support for `__all__` (#17856)
  [ty] fix assigning a typevar to a union with itself (#17910)
  [ty] Improve UX for `[duplicate-base]` diagnostics (#17914)
  Clean up some Ruff references in the ty server (#17920)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants