Add Checker::context method, deduplicate Unicode checks#19609
Merged
Conversation
Contributor
|
MichaReiser
reviewed
Jul 29, 2025
Member
MichaReiser
left a comment
There was a problem hiding this comment.
It seems to me that the only problem is that you can't go from Checker to LintContext but I don't see a reason why that should be, given that Checker stores a LintContext. Is there something that prevents us from adding a context() method to Checker that returns the LintContext?
Contributor
Author
|
I think we previously wanted to avoid providing two paths to |
Summary -- This PR is stacked on #19608 and of more dubious value. It bothered me to see that `Candidate::into_diagnostic` and `Candidate::report_diagnostic` were essentially the same, differing only in taking a `LintContext` instead of a `Checker`. This was also the only reason we needed to collect a `Vec` of `Candidate`s in `ambiguous_unicode_character` instead of reporting them directly. This PR fixes those two concerns, but at the cost of introducing a trait implemented by `LintContext` and `Checker`. I'm leaning towards it not being worth it, unless we think the trait will be useful elsewhere. If we do want to keep the trait, we could obviously move `report_diagnostic` into it and move the actual implementations into the trait impls. I held off doing that for now to avoid a big import diff, especially if we didn't want this change at all. Test Plan -- Existing tests
497d425 to
49c5d57
Compare
DiagnosticReporter trait, deduplicate Unicode checksChecker::context method, deduplicate Unicode checks
dcreager
added a commit
that referenced
this pull request
Aug 1, 2025
* main: (24 commits) Add `Checker::context` method, deduplicate Unicode checks (#19609) [`flake8-pyi`] Preserve inline comment in ellipsis removal (`PYI013`) (#19399) [ty] Add flow diagram for import resolution [ty] Add comments to some core resolver functions [ty] Add missing ticks and use consistent quoting [ty] Reflow some long lines [ty] Unexport helper function [ty] Remove offset from `CompletionTargetTokens::Unknown` [`pyupgrade`] Fix `UP030` to avoid modifying double curly braces in format strings (#19378) [ty] fix a typo (#19621) [ty] synthesize `__replace__` for dataclasses (>=3.13) (#19545) [ty] Discard `Definition`s when normalizing `Signature`s (#19615) [ty] Fix empty spans following a line terminator and unprintable character spans in diagnostics (#19535) Add `LinterContext::settings` to avoid passing separate settings (#19608) Support `.pyi` files in ruff analyze graph (#19611) [ty] Sync vendored typeshed stubs (#19607) [ty] Bump docstring-adder pin (#19606) [`perflint`] Ignore rule if target is `global` or `nonlocal` (`PERF401`) (#19539) Add license classifier back to pyproject.toml (#19599) [ty] Add stub mapping support to signature help (#19570) ...
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 PR adds a
Checker::contextmethod that returns the underlyingLintContextto unifyCandidate::into_diagnosticandCandidate::report_diagnosticin our ambiguous Unicode character checks. This avoids some duplication and also avoids collecting aVecofCandidates only to iterate over it later.Test Plan
Existing tests