Skip to content

Build a context data type from the six flags of a data type or of its manager, and a type that decodes base64 text, in one place each - #6566

Merged
Koudai Aono (koxudaxi) merged 1 commit into
nx-8from
nx-9
Nov 8, 2026
Merged

Koudai Aono (koxudaxi) merged 1 commit into
nx-8from
nx-9

Conversation

@koxudaxi

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

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Refactor
    • Streamlined how context-specific data types are created across model generation, including types for encoded strings and bytes.
    • No user-facing behavior changes are expected.

… manager, and a type that decodes base64 text, in one place each
@coderabbitai

coderabbitai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The changes add context-class methods to DataType and DataTypeManager. Msgspec uses these methods to create context-specific types. Pydantic v2 uses a shared helper to create encoded text types and set runtime imports.

Changes: Context-specific data type creation

Layer / File(s) Summary
Add context-class methods
src/datamodel_code_generator/types.py
DataType and DataTypeManager gain _context_class methods that create subclasses using their Python version and context settings.
Use context-class methods for type creation
src/datamodel_code_generator/model/msgspec.py, src/datamodel_code_generator/model/pydantic_v2/types.py
Msgspec uses the context-class methods to create types. Pydantic v2 uses _encoded_text_type for encoded bytes and strings, including runtime-import setup. The string path retains strict-mode import selection and passes strict through the helper.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Merge Risk: Minimal · up to 53bf6

No merge-blocking issue is established for this refactor. It appears mergeable subject to normal validation.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title describes the centralized creation of context data types and base64-decoding types. It is long but relevant to the main changes.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
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: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 3 files.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
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 76a13a3 and 53bf633.

Files selected for processing: 3

  • src/datamodel_code_generator/model/msgspec.py
  • src/datamodel_code_generator/model/pydantic_v2/types.py
  • src/datamodel_code_generator/types.py

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

@koxudaxi
Koudai Aono (koxudaxi) marked this pull request as ready for review November 7, 2026 18:26
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 7, 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-07T18:27:55.532079Z 53bf633 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

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

@codspeed

codspeed Bot commented Nov 7, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 49.68%

2 warnings

⚠️ 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 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

❌ 53 regressed benchmarks
⏩ 98 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_perf_client_calls[sync] 18.6 ms 43.9 ms -57.65%
❌ test_perf_client_calls[async] 20.3 ms 47.7 ms -57.47%
❌ test_perf_load_pyproject_config[mapping-None] 107.8 µs 245.9 µs -56.15%
❌ test_perf_load_pyproject_config[mapping-multiple] 117.7 µs 263.9 µs -55.4%
❌ test_perf_load_pyproject_config[config-multiple] 117.1 µs 261.3 µs -55.19%
❌ test_perf_load_pyproject_config[config-None] 105.8 µs 236.1 µs -55.18%
❌ test_perf_graphql_style_pydantic_v2 434.7 ms 952.3 ms -54.36%
❌ test_perf_extreme_large_schema 8.4 s 18.2 s -53.7%
❌ test_perf_deep_nested 2.9 s 6.3 s -53.53%
❌ test_perf_kubernetes_style_pydantic_v2 1.5 s 3.1 s -52.88%
❌ test_perf_scalar_root_collapsed_builtin 111.7 ms 235.4 ms -52.55%
❌ test_perf_unique_items_runtime_scalar_validation 1.5 ms 3.2 ms -52.16%
❌ test_perf_simple_msgspec_unset_field_rendering 280.9 ms 586.1 ms -52.07%
❌ test_perf_openapi_large 1.8 s 3.7 s -51.97%
❌ test_perf_duplicate_names 571.8 ms 1,187.6 ms -51.85%
❌ test_perf_multiple_files_input 2.2 s 4.6 s -51.82%
❌ test_perf_pydantic_field_name_resolution 1.3 ms 2.7 ms -51.71%
❌ test_perf_unique_items_nested_model_validation 1.6 ms 3.3 ms -51.54%
❌ test_perf_aws_style_openapi_pydantic_v2 1.3 s 2.6 s -51.43%
❌ test_perf_inherited_required_fields[required-derived-first] 404.3 ms 826.8 ms -51.1%
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing nx-9 (53bf633) with nx-8 (76a13a3)

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

@koxudaxi
Koudai Aono (koxudaxi) merged commit 80a20c5 into main Nov 8, 2026
41 of 144 checks passed
@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: The PR is a pure internal refactor that replaces repeated calls to the private helper _create_context_data_type with new private _context_class methods on DataType and DataTypeManager, which forward the same six context flags, and it moves a local import in pydantic_v2 types to module level and merges duplicated encoded bytes and str construction into a private _encoded_text_type helper with the same arguments and runtime imports. No public API, CLI option, template, default value, Python version support, or error handling is changed, and the behaviour diff gate only reports both-fail cells with no accepted or violation cells, so default generated output is unchanged.


This analysis was produced by the release draft workflow

@github-actions

Copy link
Copy Markdown
Contributor

🎉 Released in 0.92.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