[ty] Fix precedence of all selector in TOML configurations#23723
[ty] Fix precedence of all selector in TOML configurations#23723charliermarsh merged 3 commits intomainfrom
all selector in TOML configurations#23723Conversation
Typing conformance resultsNo changes detected ✅ |
Memory usage reportMemory usage unchanged ✅ |
|
MichaReiser
left a comment
There was a problem hiding this comment.
I don't think this fix is correct. We do want to preserve the relative order between different configuration files (or main configuration and overrides). The same problem doesn't exist for CLI arguments either.
There's an open question about whether all should always take precedence and disregard order on the CLI and in an editor configuration, even though these sources have perfectly defined ordering. Or if we should take a different approach here altogether. I don't know what the right answer to this. But ordering the rules here is incorrect as it prevents a configuration from using all to disable any rules enabled in a parent configuration.
|
Isn’t this just sorting all in front of other selectors, within a single file’s selectors? Why would this disregard relative ordering across files, as implemented? (I’m not sure that sorting in this way is stale / safe but that seems different than the concern you’re getting at.) |
|
|
d6b1618 to
57d14c8
Compare
all selector before other rulesall selector in TOML configurations
|
That makes sense, thank you. |
7e99edb to
0649d02
Compare
* main: Update conformance suite commit hash (#23746) conformance.py: Collapse the summary paragraph when nothing changed (#23745) [ty] Make inferred specializations line up with source types more better (#23715) Bump 0.15.5 (#23743) [ty] Render all changed diagnostics in conformance.py (#23613) [ty] Split deferred checks out of `types/infer/builder.rs` (#23740) Discover markdown files by default in preview mode (#23434) [ty] Use `HasOptionalDefinition` for `except` handlers (#23739) [ty] Fix precedence of `all` selector in TOML configurations (#23723) [ty] Make `all` selector case sensitive (#23713) [ty] Add a diagnostic if a `TypeVar` is used to specialize a `ParamSpec`, or vice versa (#23738) [ty] Override home directory in ty tests (#23724) [ty] More type-variable default validation (#23639) [ty] Validate bare ParamSpec usage in type annotations, and support stringified ParamSpecs as the first argument to `Callable` (#23625) [ty] Add `all` selector to ty.json's `schema` (#23721) [ty] Add quotes to related issues links (#23720) [ty] Fix panic on incomplete except handlers (#23708)
Summary
Closes astral-sh/ty#2952.
TOML tables are unordered — the spec says key/value pairs within tables are not guaranteed to be in any specific order. However, the
tomlcrate happens to sort keys lexicographically when deserializing. This means that rules likeabstract-method-in-final-classsort beforeall, so theallselector silently overrides the more-specific rule when processed sequentially.This PR fixes the issue by sorting selectors from the same configuration file so that
allis always applied first, then specific per-rule selectors are applied afterwards. This ensures that specific rules always take precedence overallwithin a given config file, regardless of lexicographic ordering.The fix is scoped to file-based configuration only — CLI argument order is still preserved as-is, since users have explicit control over ordering there.
Test plan
Added a test (
configuration_all_rules_with_rule_sorting_before_all) that usesabstract-method-in-final-class(which sorts beforeall) to verify the specific rule takes precedence.