Repository navigation
Remove the duplicates in the leaf modules: runtime type expressions, Python literals, sources, regex syntax and graphs - #5494
Conversation
…on, one literal container renderer and smaller copies
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Type expression conversion src/datamodel_code_generator/_internal_utils.py, src/datamodel_code_generator/_openapi_codec_plan.py, src/datamodel_code_generator/_python_type_annotation_codec.py, src/datamodel_code_generator/_python_type_import_registry.py, src/datamodel_code_generator/_python_type_runtime.py, src/datamodel_code_generator/parser/mcp.py |
Type annotation and runtime conversion use consolidated logic. Backport versions derive from the stable-type introduction table. The changes also remove a fallback match arm and unused imports. |
Parameter-plan serialization src/datamodel_code_generator/_target_render.py |
Parameter-plan rendering iterates dataclass fields, omits values that match declared defaults, and renders field-plan values through field_plan. |
Python literal rendering
| Layer / File(s) | Summary |
|---|---|
Container rewriting and rendering src/datamodel_code_generator/python_literal.py |
Runtime-expression rewriting handles exact built-in containers recursively. Trusted and untrusted rendering share container formatting logic, with their existing distinct set-ordering policies. |
Source parsing and cache
| Layer / File(s) | Summary |
|---|---|
Source decoding and mapping validation src/datamodel_code_generator/_source.py |
Parser-source decoding uses one function with optional digest-based caching. JSON parsing falls back to YAML on JSON decode errors, and mapping checks use a shared helper. |
Remote lock handling
| Layer / File(s) | Summary |
|---|---|
Remote URL identity and response recording src/datamodel_code_generator/remote_lock.py |
URL validation and identity use the parsed scheme. Response recording combines missing-entry and body-mismatch handling, replacing entries in update mode. |
Dynamic model handling
| Layer / File(s) | Summary |
|---|---|
Model rebuilding and extraction src/datamodel_code_generator/dynamic.py |
Single- and multi-module execution rebuild every BaseModel subclass. Model extraction applies private-name filtering directly while retaining its model and enum selection conditions. |
Graph ordering and components
| Layer / File(s) | Summary |
|---|---|
Dependency ordering and SCC selection src/datamodel_code_generator/_reference_graph.py, src/datamodel_code_generator/_scc.py |
Reference dependency ordering delegates to GroupGraph. SCC filtering uses a sorted comprehension, while traversal behavior remains unchanged. |
Regular-expression syntax analysis
| Layer / File(s) | Summary |
|---|---|
Regex scanning and pattern construction src/datamodel_code_generator/_regex_syntax.py |
Regex patterns reuse shared expressions. Lookalike checks reject lookarounds, and short lookahead lists use pairwise_patterns. |
Identifier and path validation
| Layer / File(s) | Summary |
|---|---|
Normalized identifier and path checks src/datamodel_code_generator/validators.py |
Identifier and keyword checks use normalized names. Dotted paths and import paths use the safe public type name helper. |
Priority:
Estimated code review effort: 4 (Complex) | ~35 minutes
Change: Refactor
Merge Risk: 
Minimal · up to 6d882
-
The consolidation has no established merge-blocking regression and is mergeable subject to normal checks.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passedFull details: Docstring Coverage
-
Explanation
Docstring coverage is 76.32% which is insufficient. 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 38 functions across 13 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches: 💡 1
-
📝 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.
Comment @coderabbitai help to get the list of available commands.
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. |
Merging this PR will improve performance by 97.11%2 warnings
Performance Changes
Tip Curious why performance improved? Comment Comparing Footnotes
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Breaking Change AnalysisResult: No breaking changes detected Reasoning: The diff is an internal refactor that keeps behaviour the same. It merges duplicated helpers in _python_type_runtime into one function and keeps the public python_callable_expr_from_runtime_args. It builds the typing_extensions backport table from the existing version table, shares counted-repetition and literal regex constants, sends two-pattern lookahead joining through pairwise_patterns, and shortens the SCC, reference-graph, source-loading, remote-lock, python_literal, target_render parameter_plan and validators code. Only private names are removed: _should_extract_model_name, _stringify_untrusted_value, _rebuild_runtime_container, _EMPTY_SET, _MIN_DOTTED_PATH_PARTS, _PLAN_DEFAULTS, and the noqa re-exports of _local_definition_ref_name and _rewrite_local_definition_ref from parser.mcp. No CLI option, public API, template variable, default value, Python version or error message changes. The remote lock code drops scheme lowercasing, but urlsplit already lowercases the scheme, and the http/https check still runs in _split_remote_url. In dynamic.py, model_rebuild drops the pydantic_generic_metadata check, but every pydantic v2 BaseModel already has that attribute. The behaviour gate lists accepted cells, but their notes put them on an earlier allOf change where an allOf whose parts admit no object becomes a root model or alias. This diff does not touch that logic. The other cells are both-fail or crash-fix, so they show no default-output change from this PR. This analysis was produced by the release draft workflow |
|
🎉 Released in 0.88.0 This PR is now available in the latest release. See the release notes for details. |
Summary by CodeRabbit