Skip to content

Build private mutable dataclasses without generating their methods - #6764

Merged
Koudai Aono (koxudaxi) merged 1 commit into
mainfrom
mutable-records
Nov 12, 2026
Merged

Koudai Aono (koxudaxi) merged 1 commit into
mainfrom
mutable-records

Conversation

@koxudaxi

@koxudaxi Koudai Aono (koxudaxi) commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Documentation
    • Clarified how runtime state records differ from other internal records in the architecture documentation.
  • Refactor
    • Updated internal records used during parsing and generation to support mutable state. No changes to public declarations or user-facing behavior are noted.

@koxudaxi
Koudai Aono (koxudaxi) marked this pull request as ready for review November 12, 2026 07:33
@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The plain-record builder gains mutable-record support and additional initialization options. Internal utility, model, and parser declarations switch to mutable_record. The architecture documentation describes run-filled internal state using this decorator.

Changes: Mutable record support

Layer / File(s) Summary
Extend the record builder
src/datamodel_code_generator/_records.py
The builder adds mutable-record construction, supports excluded and keyword-only fields, and configures hashing. Plain frozen records without class docstrings use dataclass instead.
Adopt mutable records in utilities and model metadata
src/datamodel_code_generator/_builtin_line_split.py, src/datamodel_code_generator/_naming_hint.py, src/datamodel_code_generator/_parse_memo.py, src/datamodel_code_generator/_user_keys.py, src/datamodel_code_generator/model/*
Utility and model declarations switch to mutable_record; their fields and other described logic remain unchanged.
Adopt mutable records in parser state and planning
src/datamodel_code_generator/parser/*, src/datamodel_code_generator/parser/_passes/_state.py, docs/architecture.md
Parser declarations switch to mutable_record. The architecture documentation describes run-filled internal state as mutable records.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Possibly related PRs

Merge Risk: Minimal · up to 2e7a3

This change moves internal classes to a project decorator and extends the record builder. No concrete merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title says the PR builds private mutable dataclasses without generating their methods. The raw summary shows a new mutable_record decorator in _records.py. It supports eq, slots, and `kw_o…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title says the PR builds private mutable dataclasses without generating their methods. The raw summary shows a new mutable_record decorator in _records.py. It supports eq, slots, and kw_only options, and plain classes use a custom builder. Many private classes across the parser and model modules switch from dataclass(slots=True) to @mutable_record(slots=True). The title covers the main change, though it is slightly technical and does not mention the switch from dataclass to mutable_record across modules.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 82dbcc2 and 2e7a3c5.

Files ignored due to path filters: 1

  • docs/llms-full.txt is excluded by none and included by none
Files selected for processing: 15

  • docs/architecture.md
  • src/datamodel_code_generator/_builtin_line_split.py
  • src/datamodel_code_generator/_naming_hint.py
  • src/datamodel_code_generator/_parse_memo.py
  • src/datamodel_code_generator/_records.py
  • src/datamodel_code_generator/_user_keys.py
  • src/datamodel_code_generator/model/_field_imports.py
  • src/datamodel_code_generator/model/runtime_validation.py
  • src/datamodel_code_generator/parser/_model_shapes.py
  • src/datamodel_code_generator/parser/_naming.py
  • src/datamodel_code_generator/parser/_passes/_state.py
  • src/datamodel_code_generator/parser/_schema_graph.py
  • src/datamodel_code_generator/parser/_tag_plan.py
  • src/datamodel_code_generator/parser/base.py
  • src/datamodel_code_generator/parser/generation.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T07:36:08.582459Z 2e7a3c5 Draft marked ready
ℹ️ About Codex in GitHub

Your 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.

@github-actions

Copy link
Copy Markdown
Contributor

@codspeed

codspeed Bot commented Nov 12, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ Walltime results may be unreliable

Some benchmarks used the Walltime instrument outside CodSpeed Macro Runners, which can make the results inconsistent.

Learn more about Macro Runners

See affected benchmarks

✅ 53 untouched benchmarks
⏩ 98 skipped benchmarks1


Comparing mutable-records (2e7a3c5) with main (82dbcc2)

Open in CodSpeed

Footnotes

  1. 98 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@codecov

codecov Bot commented Nov 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@koxudaxi
Koudai Aono (koxudaxi) merged commit 57f7893 into main Nov 12, 2026
117 checks passed
@koxudaxi
Koudai Aono (koxudaxi) deleted the mutable-records branch November 12, 2026 08:36
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: This PR is an internal refactor. It adds a mutable_record decorator to the private _records module and swaps plain dataclass decorators for it on internal state classes such as _PipelineRun, TagPlan, GenerationFacts, _BracketTracker, NamingHint, ModelNameRecord, SchemaRuntimeValidation and DroppedConstraints. The decorator is built to produce the same class that dataclass without frozen produces: assignable fields, hash set to None when eq is on, and the same slots and kw_only options. The record builder now also handles fields marked init=False, keyword-only fields and docstring detection. The diff removes no command-line options, public Python names, template variables or Python version support. The only removed lines are internal imports, private helpers in _records.py and decorator lines. Dropping the unused dataclass import from parser.base does not remove a public name, since it is a standard-library import and not part of the module's API. The behaviour diff gate lists only both-fail cells and no accepted or violation cells, so default generated output does not change. Error handling is also unchanged. The changes do not touch the new read-object-keywords-by-type options or the new presets.


This analysis was produced by the release draft workflow

@github-actions

Copy link
Copy Markdown
Contributor

🎉 Released in 0.95.0

This PR is now available in the latest release. See the release notes for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant