Repository navigation
ruff_python_dto_check: add class_with_decorator matcher - #128
Merged
Merged
Conversation
Data-shaped Python (dataclasses, attrs, pydantic) lives in decorated classes, which the harvester could not see: it matched only top-level decorated functions. The new kind matches top-level decorated classes with the same decorator selector and emits class.name, class.bases, class.decorators, class.fields (annotated assignments), class.methods, class.body.source and class.range.*, plus the existing decorator.* paths. The function matcher now applies only function rules (it previously ran every rule regardless of kind), the decorator selector is shared by both matchers, harvest_with_config merges both in source order, and the AST hash locates its statement by start line so class bundles hash their own body instead of an empty one. Existing function hashes and golden outputs are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMMCqUkM2QW7zqLC2NJ
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMMCqUkM2QW7zqLC2NJ
AdaWorldAPI
marked this pull request as ready for review
October 30, 2026 14:56
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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
ruff_python_dto_checkmatched only top-level decorated functions. Python code that models data as decorated classes, such as@dataclass, attrs or pydantic, was invisible to it. Run on Mistaber's HLL compiler (BrainyBlaze/mistaber,mistaber/dsl/compiler/), it matched nothing, although that package defines its AST as 21@dataclassclasses.This adds a second matcher kind,
class_with_decorator. It matches top-level classes with the same decorator selector used for functions and emits these paths:class.nameandclass.decoratorsclass.bases: base classes and keywords, as raw source textclass.fields:{name, annotation, default}for each annotated assignment in the class bodyclass.methods: names of the functions defined in the class bodyclass.body.sourceandclass.range.line_start/class.range.line_enddecorator.raw,decorator.args[i]anddecorator.kwargs.<k>Classes nested inside other classes or functions are not matched, the same top-level policy as for functions. The class name is stored in the existing
function_namefield so that consumers of the bundle format keep working.Changes to existing behaviour:
function_with_decoratorrules. Before, it applied every rule regardless of kind, so a class rule would also have matched decorated functions.matcher/decorator.rsand is shared by both matchers. The decorator emit paths are also shared.matcher::harvest_with_configmerges function and class bundles in source order, and the CLI uses it.compute_ast_hashnow finds the top-level statement by its start line instead of by function name. Class bundles therefore hash their own body; looking them up by function name would have given every class the empty-body hash. Function hashes are unchanged, and the golden tests pass unmodified.The JSON schema, the README scope section and a new
examples/dataclass.config.jsonare updated to match.Test Plan
cargo test -p ruff_python_dto_check: all suites pass, including the newtests/class_matcher_test.rs(6 tests). The fixture has decorated, undecorated, differently decorated and nested classes, plus a decorated function whose decorator name matches the class rule. The tests assert:fields,bases,methodsanddecorator.kwargsvalues;cargo clippy -p ruff_python_dto_check --all-targets -- -D warningsandcargo fmt -p ruff_python_dto_check --checkare clean on the pinned toolchain.ruff-py-dto harvest --config examples/dataclass.config.jsonfinds exactly the 21@dataclassclasses that Python's ownastmodule counts. None of them has the empty-body hash.Generated by Claude Code