You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Build type-map entries without validating their values again - #6746
The change adds cached construction layouts for context-specific DataType classes and validation helpers for creating data types and import types. Shared and Pydantic v2 type maps now use these helpers. A test checks that an external subclass validator applies to mapped types.
Changes: Type Construction and Mapping
Layer / File(s)
Summary
Context-class construction src/datamodel_code_generator/types.py
DataType delegates union normalization and part linking to _link_parts. Context-specific classes cache validated layouts, which the construction helpers use to create instances directly.
Shared type-map construction src/datamodel_code_generator/model/types.py
Primitive, standard-library, and optional datetime mappings use _valid_data_type or _valid_import_type. The mapping associations remain unchanged.
Pydantic v2 mappings and validation test src/datamodel_code_generator/model/pydantic_v2/types.py, tests/test_types.py
Pydantic v2 mappings use _valid_import_type with the existing mapping conditions and imports. The test checks that an external DataType subclass validator applies to integer and password mappings.
This change speeds up type-map construction while keeping the same mapped types and imports. Only a hypothetical undocumented override of from_import could behave differently. No material merge risk was found.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title states the main change: type-map entries are now built without re-validating their values. The raw summary confirms this. Type-map construction in types.py, pydantic_v2/types.py, and the Dat…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title states the main change: type-map entries are now built without re-validating their values. The raw summary confirms this. Type-map construction in types.py, pydantic_v2/types.py, and the DataType layout caching all route through _valid_data_type and _valid_import_type to skip revalidation. The title is specific and matches the commit intent, so it passes.
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.
1794-1794: Minor · Data Integrity & Integration · Quick win
Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.
Preserve omitted arguments when calling an external from_import override.
An unregistered DataType subclass can override from_import with a different default for strict. A type-map call that previously omitted strict now passes strict=False, so the override produces a different mapped type. An override that accepts only the import also now raises TypeError in the shared type-map factory. Forward only arguments that the helper’s caller supplied. (raw.githubusercontent.com)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.
Reasoning: This PR is an internal speed-up and does not break anything. It adds private helpers (_valid_data_type, _valid_import_type, _build_valid, _link_parts, _valid_layout) that build DataType objects for the internal context classes without running pydantic validation again. The type map factories in model/types.py and model/pydantic_v2/types.py now call these helpers instead of data_type.from_import and data_type(...). The union folding and parent-linking code that ran in DataType.init moved, unchanged, into _link_parts, and init still calls it. The fast path only applies to exact context classes created over DataType. Any other class, including external DataType subclasses, still goes through normal construction and from_import, and a new test checks that their validators still run. No public option, parameter, class, enum value or function was removed or renamed. No CLI options, templates, defaults, Python version support or error handling changed. The behaviour diff for default options lists only both-fail cells, with no accepted or violation cells, so the generated output is the same as in release 0.94.0.
This analysis was produced by the release draft workflow
This PR is now available in the latest release. See the release notes for details.
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
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 by CodeRabbit