[ty] Only calculate information for unresolved-reference subdiagnostic if we know we'll emit the diagnostic#18465
Merged
AlexWaygood merged 1 commit intomainfrom Jun 4, 2025
Merged
Conversation
Contributor
|
…c if we know we'll emit the diagnostic
f95171c to
de23fec
Compare
carljm
approved these changes
Jun 4, 2025
Contributor
There was a problem hiding this comment.
I don't see where this is delaying work compared to the prior version from #18444? It seems like in both the old and new version, all the work is in deciding whether an attribute exists in the first place, and in both old and new, that work is done if we are definitely going to emit a diagnostic, and not otherwise. Edit: ah, never mind, I forgot about the early return if context.report_lint(...) returns None.
But this looks like a nice refactor to collect more of the work in one place, either way!
carljm
added a commit
to mtshiba/ruff
that referenced
this pull request
Jun 4, 2025
* main: [ty] Only calculate information for unresolved-reference subdiagnostic if we know we'll emit the diagnostic (astral-sh#18465)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This optimizes some of the logic added in #18444. In general, we only calculate information for subdiagnostics if we know we'll actually emit the diagnostic. The check to see whether we'll emit the diagnostic is work we'll definitely have to do whereas the the work to gather information for a subdiagnostic isn't work we necessarily have to do if the diagnostic isn't going to be emitted at all.
This PR makes us lazier about gathering the information we need for the subdiagnostic, and moves all the subdiagnostic logic into one function rather than having some
unresolved-referencesubdiagnostic logic ininfer.rsand some indiagnostic.rs.Test Plan
cargo test -p ty_python_semantic