Add GenerateConfig class and auto-generate TypedDicts for type-safe config#2844
Add GenerateConfig class and auto-generate TypedDicts for type-safe config#2844
Conversation
|
Warning Rate limit exceeded@koxudaxi has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 2 minutes and 3 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdd Pydantic config models and TypedDicts, thread an optional Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant User
participant Generate as generate()
participant ConfigModel as GenerateConfig
participant Loader as __main__/_load_model_schema
participant Parser as Parser/Codegen
User->>Generate: call generate(input_, config=GenerateConfig(...))
activate Generate
Generate->>ConfigModel: validate/read config (model_dump / attributes)
ConfigModel-->>Generate: return config values
Note right of Generate: merge/override explicit kwargs with config values
Generate->>Loader: load input models / _load_model_schema(obj)
activate Loader
Loader->>Loader: if obj has model_rebuild -> call _try_rebuild_model(obj)
Loader-->>Generate: return model/schema
deactivate Loader
Generate->>Parser: build ParserConfig/ParseConfig and run parsing/generation
activate Parser
Parser-->>Generate: generated modules/text
deactivate Parser
Generate-->>User: return generated output
deactivate Generate
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
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 |
|
📚 Docs Preview: https://pr-2844.datamodel-code-generator.pages.dev |
CodSpeed Performance ReportMerging #2844 will not alter performanceComparing
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2844 +/- ##
========================================
Coverage 99.52% 99.52%
========================================
Files 90 91 +1
Lines 14938 15360 +422
Branches 1788 1792 +4
========================================
+ Hits 14867 15287 +420
- Misses 38 39 +1
- Partials 33 34 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
9741888 to
cf8553a
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
♻️ Duplicate comments (1)
src/datamodel_code_generator/config.py (1)
11-11: Unused TypedDict imports flagged by static analysis.These imports (
GenerateConfigDict,ParseConfigDict,ParserConfigDict) are not used in this file. If they're intended for re-export, consider adding them to an__all__list or moving them to__init__.py. Otherwise, they can be removed.
🧹 Nitpick comments (1)
src/datamodel_code_generator/__main__.py (1)
762-791: Consider removing unusednoqadirectives.The static analysis indicates that the
# noqa: PLC0415directives on lines 768, 769, 772, and 774 are unused. This suggests thePLC0415rule (import not at top of file) may not be enabled in the project's linter configuration.🔎 Suggested fix
- from datamodel_code_generator.model.base import DataModel, DataModelFieldBase # noqa: PLC0415 - from datamodel_code_generator.types import DataTypeManager, StrictTypes # noqa: PLC0415 + from datamodel_code_generator.model.base import DataModel, DataModelFieldBase + from datamodel_code_generator.types import DataTypeManager, StrictTypes try: - from datamodel_code_generator.model.pydantic_v2 import UnionMode # noqa: PLC0415 + from datamodel_code_generator.model.pydantic_v2 import UnionMode except ImportError: - from typing import Any # noqa: PLC0415 + from typing import Any
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (14)
.github/workflows/config-types.yaml.pre-commit-config.yamlpyproject.tomlsrc/datamodel_code_generator/__init__.pysrc/datamodel_code_generator/__main__.pysrc/datamodel_code_generator/_types/__init__.pysrc/datamodel_code_generator/_types/generate_config_dict.pysrc/datamodel_code_generator/_types/parse_config_dict.pysrc/datamodel_code_generator/_types/parser_config_dict.pysrc/datamodel_code_generator/config.pytests/main/test_main_general.pytests/main/test_public_api_signature_baseline.pytests/test_input_model.pytox.ini
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-12-25T09:22:14.661Z
Learnt from: koxudaxi
Repo: koxudaxi/datamodel-code-generator PR: 2799
File: src/datamodel_code_generator/model/pydantic/__init__.py:43-43
Timestamp: 2025-12-25T09:22:14.661Z
Learning: In datamodel-code-generator project, defensive `# noqa: PLC0415` directives should be kept on lazy imports (imports inside functions/methods) even when Ruff reports them as unused via RUF100, to prepare for potential future Ruff configuration changes that might enable the import-outside-top-level rule.
Applied to files:
src/datamodel_code_generator/config.py
🧬 Code graph analysis (7)
src/datamodel_code_generator/__main__.py (5)
src/datamodel_code_generator/model/base.py (3)
class_name(847-849)class_name(852-856)model_rebuild(199-206)src/datamodel_code_generator/model/pydantic/types.py (1)
DataTypeManager(171-372)src/datamodel_code_generator/model/pydantic_v2/types.py (1)
DataTypeManager(70-167)src/datamodel_code_generator/enums.py (2)
StrictTypes(199-206)UnionMode(192-196)src/datamodel_code_generator/parser/jsonschema.py (1)
model_rebuild(224-226)
src/datamodel_code_generator/__init__.py (1)
src/datamodel_code_generator/config.py (1)
GenerateConfig(78-208)
src/datamodel_code_generator/_types/generate_config_dict.py (3)
src/datamodel_code_generator/enums.py (15)
AllExportsCollisionStrategy(92-102)AllExportsScope(81-89)AllOfMergeMode(142-152)CollapseRootModelsNameStrategy(131-139)FieldTypeCollisionStrategy(105-113)GraphQLScope(155-158)InputFileType(35-45)ModuleSplitMode(172-178)NamingStrategy(116-128)OpenAPIScope(70-78)ReadOnlyWriteOnlyModelType(161-169)ReuseScope(59-67)TargetPydanticVersion(181-189)UnionMode(192-196)StrictTypes(199-206)src/datamodel_code_generator/format.py (4)
DateClassType(60-65)DatetimeClassType(50-57)Formatter(171-177)PythonVersion(68-140)src/datamodel_code_generator/parser/__init__.py (1)
LiteralType(20-25)
src/datamodel_code_generator/_types/parse_config_dict.py (1)
src/datamodel_code_generator/enums.py (3)
AllExportsCollisionStrategy(92-102)AllExportsScope(81-89)ModuleSplitMode(172-178)
src/datamodel_code_generator/_types/__init__.py (3)
src/datamodel_code_generator/_types/generate_config_dict.py (1)
GenerateConfigDict(35-155)src/datamodel_code_generator/_types/parse_config_dict.py (1)
ParseConfigDict(14-21)src/datamodel_code_generator/_types/parser_config_dict.py (1)
ParserConfigDict(27-137)
src/datamodel_code_generator/config.py (5)
src/datamodel_code_generator/_types/generate_config_dict.py (1)
GenerateConfigDict(35-155)src/datamodel_code_generator/_types/parse_config_dict.py (1)
ParseConfigDict(14-21)src/datamodel_code_generator/parser/__init__.py (2)
DefaultPutDict(28-47)LiteralType(20-25)src/datamodel_code_generator/util.py (2)
is_pydantic_v2(52-57)model_dump(254-258)src/datamodel_code_generator/model/__init__.py (1)
DataModelSet(25-35)
tests/main/test_public_api_signature_baseline.py (1)
src/datamodel_code_generator/config.py (1)
GenerateConfig(78-208)
🪛 GitHub Actions: Lint
tox.ini
[error] 1-1: Command 'tox' not found in the environment during config-types hook.
src/datamodel_code_generator/config.py
[error] 83-83: ruff: D106 Missing docstring in public nested class
[error] 216-216: ruff: D106 Missing docstring in public nested class
[error] 399-399: ruff: D106 Missing docstring in public nested class
🪛 Ruff (0.14.10)
src/datamodel_code_generator/__main__.py
768-768: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
769-769: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
772-772: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
774-774: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
src/datamodel_code_generator/__init__.py
606-606: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
src/datamodel_code_generator/config.py
437-437: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
438-438: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
441-441: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- GitHub Check: 3.11 on macOS
- GitHub Check: py312-black24 on Ubuntu
- GitHub Check: 3.10 on Windows
- GitHub Check: 3.10 on macOS
- GitHub Check: 3.10 on Ubuntu
- GitHub Check: 3.11 on Windows
- GitHub Check: 3.13 on Windows
- GitHub Check: 3.12 on Windows
- GitHub Check: 3.14 on Windows
- GitHub Check: benchmarks
🔇 Additional comments (18)
tests/test_input_model.py (1)
595-603: LGTM!The test properly validates that
GenerateConfigcan be used as an input model and generates the expected TypedDict output with callable type annotations. The test follows the established patterns in this file and is correctly guarded withSKIP_PYDANTIC_V1..github/workflows/config-types.yaml (1)
1-29: LGTM!The workflow is well-structured with appropriate path filters to trigger only when config-related files change. The use of
astral-sh/setup-uvwith caching andtox-uvfollows modern Python CI patterns.tests/main/test_main_general.py (1)
1972-1994: LGTM!The test properly validates the new
GenerateConfig-based API. Themodel_rebuildcall with_types_namespacecorrectly resolves forward references forStrictTypesandUnionMode, which is necessary for Pydantic v2 models with deferred annotations.tox.ini (1)
115-122: LGTM!The new
config-typesenvironment is correctly configured with the three profile commands and appropriate dependency groups. The{posargs}usage allows the--checkflag to be passed from CI.Note: The pipeline failure ("Command 'tox' not found") appears to be a pre-commit hook configuration issue, not a problem with this tox configuration itself.
src/datamodel_code_generator/_types/parser_config_dict.py (1)
1-137: LGTM!This auto-generated TypedDict correctly captures the parser configuration schema with appropriate
NotRequiredannotations for all optional fields. The imports from internal modules are necessary for proper type annotations.src/datamodel_code_generator/__main__.py (1)
872-874: LGTM!The integration of
_try_rebuild_modelbefore callingmodel_json_schemaensures that config models have their forward references properly resolved before schema generation. This is essential for models likeGenerateConfigthat reference types likeStrictTypesandUnionMode.tests/main/test_public_api_signature_baseline.py (2)
37-37: LGTM!The
GenerateConfigimport is correctly placed underTYPE_CHECKINGsince it's only used for type annotations in the baseline signature.
49-49: LGTM!The
configparameter addition to the baseline signature correctly reflects the newgenerate()API, ensuring the signature baseline test will validate the new config-driven interface.src/datamodel_code_generator/_types/__init__.py (1)
1-9: LGTM!Clean public API surface for the auto-generated TypedDict configurations. The explicit
__all__list and descriptive module docstring follow best practices for public-facing package exports..pre-commit-config.yaml (1)
40-45: LGTM!The new pre-commit hook follows the same pattern as the existing
readmehook and correctly triggers TypedDict generation whenconfig.pychanges. The chained profile invocations ensure all three config TypedDicts stay in sync.src/datamodel_code_generator/_types/parse_config_dict.py (1)
1-21: Auto-generated TypedDict looks correct.This file is generated by
datamodel-codegenand the fields align with theParseConfigmodel inconfig.py. The types and imports are consistent with the enum definitions in the codebase.pyproject.toml (1)
262-287: Well-structured configuration profiles.The
config-types-baseprofile provides sensible defaults (enum literals off, standard primitives, TypedDict output), and the three specific profiles correctly extend it with their respective input models and output paths. Thetype_overridesmapping ensures generated TypedDicts reference actual enum types rather than inlining literals.src/datamodel_code_generator/_types/generate_config_dict.py (1)
1-155: Comprehensive auto-generated TypedDict.This generated file correctly captures the full configuration surface of
GenerateConfig. The imports properly reference enum types from their respective modules, and theNotRequiredwrapper on all fields enables type-safe partial configuration. The generated output aligns with the source model.src/datamodel_code_generator/__init__.py (2)
606-608: Keep the defensive# noqa: PLC0415directive.Based on project learnings, defensive
# noqa: PLC0415directives should be kept on lazy imports (imports inside functions/methods) even when Ruff reports them as unused via RUF100. This prepares for potential future Ruff configuration changes.
587-768: Config extraction logic is comprehensive and consistent.The merge logic correctly prioritizes explicit parameters over config values using appropriate patterns for each type:
Nonechecks for optional parameters- Equality checks against defaults for enum/non-boolean parameters
orfor boolean flags (though see note aboutuse_standard_collections)The
extra_template_dataconversion fromdicttodefaultdict(lines 605-608) correctly bridges the type difference betweenGenerateConfigand the function's internal usage.src/datamodel_code_generator/config.py (3)
437-441: Keep the defensive# noqa: PLC0415directives.Per project learnings, these directives should be retained on lazy imports to prepare for potential future Ruff configuration changes, even when currently reported as unused.
333-393: Well-designed factory method with proper field derivation.The
_from_generate_configfactory elegantly:
- Uses field intersection (
set(parser_fields) & set(generate_fields)) for automatic field mapping- Applies business logic for computed fields (e.g.,
effective_dataclass_arguments,effective_enum_field_as_literal)- Correctly handles the
output_model_type-dependent defaults for enum behavior- Filters the final dict to only valid
ParserConfigfieldsThis approach is maintainable as new fields added to both configs will automatically propagate.
430-463: Correct forward reference resolution mechanism.The rebuild function properly:
- Guards against redundant rebuilds with
_CONFIG_MODELS_STATE- Handles the optional
UnionModeimport gracefully (falls back toAny)- Uses the appropriate Pydantic version-specific method (
model_rebuildvsupdate_forward_refs)- Includes all necessary types in the namespace for forward reference resolution
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/datamodel_code_generator/__main__.py (1)
766-794: Keep# noqa: PLC0415directives for defensive purposes.Based on learnings, the
# noqa: PLC0415directives on lines 772-778 should be kept even though Ruff reports them as unused (RUF100). These are defensive directives for lazy imports that protect against future Ruff configuration changes that might enable theimport-outside-top-levelrule.Module name check may be too broad.
The check
module in {"datamodel_code_generator.config", "config"}on line 771 includes the bare"config"string. This could match unrelated modules namedconfigfrom other packages. Consider restricting to just the fully qualified module name unless there's a specific use case for the short form.🔎 Suggested refinement
- if module in {"datamodel_code_generator.config", "config"} and class_name in config_classes: + if module == "datamodel_code_generator.config" and class_name in config_classes:
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
.github/workflows/lint.yaml.pre-commit-config.yamlpyproject.tomlsrc/datamodel_code_generator/__main__.pysrc/datamodel_code_generator/config.py
🚧 Files skipped from review as they are similar to previous changes (1)
- .pre-commit-config.yaml
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-12-25T09:22:14.661Z
Learnt from: koxudaxi
Repo: koxudaxi/datamodel-code-generator PR: 2799
File: src/datamodel_code_generator/model/pydantic/__init__.py:43-43
Timestamp: 2025-12-25T09:22:14.661Z
Learning: In datamodel-code-generator project, defensive `# noqa: PLC0415` directives should be kept on lazy imports (imports inside functions/methods) even when Ruff reports them as unused via RUF100, to prepare for potential future Ruff configuration changes that might enable the import-outside-top-level rule.
Applied to files:
src/datamodel_code_generator/config.py
🧬 Code graph analysis (2)
src/datamodel_code_generator/__main__.py (1)
src/datamodel_code_generator/parser/jsonschema.py (1)
model_rebuild(224-226)
src/datamodel_code_generator/config.py (4)
src/datamodel_code_generator/parser/__init__.py (1)
DefaultPutDict(28-47)src/datamodel_code_generator/util.py (3)
is_pydantic_v2(52-57)model_dump(254-258)model_validate(261-265)src/datamodel_code_generator/model/__init__.py (1)
DataModelSet(25-35)src/datamodel_code_generator/parser/base.py (1)
parent(603-605)
🪛 Ruff (0.14.10)
src/datamodel_code_generator/__main__.py
772-772: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
773-773: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
776-776: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
778-778: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
src/datamodel_code_generator/config.py
439-439: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
440-440: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
443-443: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
- GitHub Check: py312-pydantic1 on Ubuntu
- GitHub Check: 3.14 on Windows
- GitHub Check: py312-black23 on Ubuntu
- GitHub Check: 3.11 on macOS
- GitHub Check: py312-black24 on Ubuntu
- GitHub Check: 3.12 on Windows
- GitHub Check: 3.10 on Windows
- GitHub Check: 3.11 on Windows
- GitHub Check: 3.13 on Ubuntu
- GitHub Check: 3.13 on Windows
- GitHub Check: benchmarks
- GitHub Check: Analyze (python)
🔇 Additional comments (10)
src/datamodel_code_generator/__main__.py (2)
651-657: LGTM! Proper handling oftypes.UnionTypefor Python 3.10+ union syntax.The implementation correctly detects
UnionType(fromX | Ysyntax) and serializes it with the" | "separator format. The use ofgetattr(origin, "__name__", None) == "UnionType"is a safe way to check without importingtypes.UnionTypewhich may not exist in all Python versions.
876-878: LGTM! Proper integration of model rebuild before schema generation.The guard
hasattr(obj, "model_rebuild")correctly ensures Pydantic v2 compatibility, and calling_try_rebuild_modelbeforemodel_json_schema()ensures forward references are resolved.pyproject.toml (2)
247-247: LGTM! Appropriate exclusion of generated type files from coverage.Excluding
src/datamodel_code_generator/_types/*from coverage is correct since these are auto-generated TypedDict files that don't need test coverage tracking.
262-287: Well-structured profile configuration for auto-generating config TypedDicts.The profile hierarchy is clean:
config-types-basedefines shared settings (formatters, type overrides, output model type)- Child profiles (
generate-config-dict,parser-config-dict,parse-config-dict) extend the base with specificinput-modelandoutputpathsThe comprehensive
type_overridesmapping ensures enum types likeInputFileType,DataModelType, etc., are preserved with their proper qualified paths in the generated TypedDicts.src/datamodel_code_generator/config.py (6)
50-73: Well-designed conditional type alias handling for Pydantic v1/v2 compatibility.The three-way branching (
TYPE_CHECKING,is_pydantic_v2(), else) elegantly handles:
- Static type checking with simple aliases
- Pydantic v2 runtime with
Annotated+WithJsonSchemafor proper schema generation- Pydantic v1 fallback with plain types
This ensures proper JSON Schema output while maintaining type safety.
76-88: LGTM! Proper Pydantic v1/v2 configuration setup.The conditional handling of
model_config(v2) vs nestedConfigclass (v1) is correct. The docstring at line 84 addresses the previous D106 pipeline failure.
335-393: Well-implemented factory method for ParserConfig creation.The
_from_generate_configclassmethod properly:
- Computes effective values (
effective_dataclass_arguments,effective_enum_field_as_literal,effective_set_default_enum_member)- Uses field intersection to safely copy matching fields between configs
- Adds parser-specific fields (
data_model_type,base_path,remote_text_cache, etc.)- Uses version-compatible
model_dumpandmodel_validateutilities
248-248: Verify intentional default difference foruse_standard_collections.
ParserConfig.use_standard_collectionsdefaults toFalsewhileGenerateConfig.use_standard_collectionsdefaults toTrue. When using_from_generate_config, theGenerateConfigvalue is copied, so this only affects directParserConfiginstantiation.Is this default difference intentional for the direct instantiation use case?
396-429: LGTM! Clean implementation of ParseConfig.The class is focused on parse-time options with a straightforward
_from_generate_configfactory method using field intersection.
435-465: LGTM! Proper forward reference resolution with version compatibility.The function correctly:
- Uses state tracking to avoid redundant rebuilds
- Builds a types namespace with all required types
- Handles
UnionModeimport failure gracefully- Uses version-appropriate methods (
model_rebuildvsupdate_forward_refs)Keep
# noqa: PLC0415directives for defensive purposes.Per learnings from this repository, the
# noqa: PLC0415directives on lines 439, 440, and 443 should be retained even though Ruff reports them as unused. These protect against future Ruff configuration changes that might enable theimport-outside-top-levelrule.
d54165a to
c12a383
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
tests/test_format.py (1)
165-179: Tests match implementation but stdin usage is missing required--stdin-filenameargumentThe test expectations correctly reflect the current implementation, but there's a critical issue: Ruff documentation explicitly requires
--stdin-filenamewhen reading from stdin. The current calls toruff check --fix -andruff format -are incomplete per Ruff's documented CLI behavior.For stdin operations (lines 165-179, and the
apply_ruff_lint,apply_ruff_formatter,apply_ruff_check_and_formatmethods), add the required--stdin-filenameargument:("ruff", "check", "--fix", "--stdin-filename", "input.py", "-") ("ruff", "format", "--stdin-filename", "input.py", "-")Directory-based formatting tests (lines 216-235, 258-283, 302-330) are correct and need no changes.
🧹 Nitpick comments (3)
.pre-commit-config.yaml (1)
21-24: Ruff excludes and config-types hook are wired sensiblyExcluding both
tests/dataandsrc/datamodel_code_generator/_types/from Ruff makes sense for test fixtures and generated TypedDicts, and the newconfig-typeslocal hook is consistent with the existingreadmehook pattern (fixed env, no filenames, tightfilesfilter onconfig.py). This should keep the generated config types in sync without surprising other commits.Also applies to: 40-45
src/datamodel_code_generator/__init__.py (2)
63-67: GenerateConfig integration and precedence logic look consistentImporting
GenerateConfigonly underTYPE_CHECKINGkeeps runtime imports clean, and the newconfigparameter is threaded intogenerate()in a way that’s broadly consistent:
- For most value/optional parameters (paths, enums, mappings), you use the “argument if provided, otherwise config” pattern (
x = config.x if x is default/None else x), which keeps existing call sites stable while lettingGenerateConfigact as a central default.- For booleans defaulting to
False,flag = flag or config.flagsensibly treats config as the default and can’t distinguish explicitFalsefrom defaultFalse, which is expected with simple booleans.- For booleans defaulting to
True(use_standard_collections,use_specialized_enum,use_union_operator), theconfig.value if param else False/parampattern preserves explicitFalsewhile letting config drive the default when callers leave the parameter at its defaultTrue. This matches the agreed pattern from earlier fixes in this module.extra_template_datais correctly upgraded from a plaindicton the config into adefaultdict(dict, ...)only when no explicitextra_template_datais passed, and your tests exercise the “config vs direct override” behavior.Overall, the config-driven path looks coherent and backwards compatible with existing
generate()usage.Also applies to: 451-575, 587-770
516-516: Wiregraphql_scopestoGraphQLParseror remove the parameter fromgenerate()The
graphql_scopesparameter is accepted and merged fromGenerateConfigingenerate()(line 678), but is not passed toGraphQLParserviakwargswheninput_file_type == InputFileType.GraphQL(lines 845–857). Additionally,GraphQLParser.__init__does not accept agraphql_scopesparameter. Either addgraphql_scopessupport toGraphQLParserand wire it through alongsidedata_model_scalar_typeanddata_model_union_type(lines 930–938), or remove the parameter fromgenerate()to avoid confusion with unused configuration.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (17)
.github/workflows/config-types.yaml.github/workflows/lint.yaml.pre-commit-config.yamlpyproject.tomlsrc/datamodel_code_generator/__init__.pysrc/datamodel_code_generator/__main__.pysrc/datamodel_code_generator/_types/__init__.pysrc/datamodel_code_generator/_types/generate_config_dict.pysrc/datamodel_code_generator/_types/parse_config_dict.pysrc/datamodel_code_generator/_types/parser_config_dict.pysrc/datamodel_code_generator/config.pysrc/datamodel_code_generator/format.pytests/main/test_main_general.pytests/main/test_public_api_signature_baseline.pytests/test_format.pytests/test_input_model.pytox.ini
🚧 Files skipped from review as they are similar to previous changes (9)
- src/datamodel_code_generator/_types/parser_config_dict.py
- src/datamodel_code_generator/_types/parse_config_dict.py
- .github/workflows/config-types.yaml
- tox.ini
- src/datamodel_code_generator/_types/init.py
- tests/main/test_public_api_signature_baseline.py
- .github/workflows/lint.yaml
- pyproject.toml
- src/datamodel_code_generator/_types/generate_config_dict.py
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-12-18T13:43:16.235Z
Learnt from: koxudaxi
Repo: koxudaxi/datamodel-code-generator PR: 2681
File: tests/cli_doc/test_cli_doc_coverage.py:82-82
Timestamp: 2025-12-18T13:43:16.235Z
Learning: In datamodel-code-generator project, Ruff preview mode is enabled via `lint.preview = true` in pyproject.toml. This enables preview rules like PLR6301 (no-self-use), so `noqa: PLR6301` directives are necessary and should not be removed even if RUF100 suggests they are unused.
Applied to files:
src/datamodel_code_generator/format.py.pre-commit-config.yaml
📚 Learning: 2025-12-25T09:22:14.661Z
Learnt from: koxudaxi
Repo: koxudaxi/datamodel-code-generator PR: 2799
File: src/datamodel_code_generator/model/pydantic/__init__.py:43-43
Timestamp: 2025-12-25T09:22:14.661Z
Learning: In datamodel-code-generator project, defensive `# noqa: PLC0415` directives should be kept on lazy imports (imports inside functions/methods) even when Ruff reports them as unused via RUF100, to prepare for potential future Ruff configuration changes that might enable the import-outside-top-level rule.
Applied to files:
src/datamodel_code_generator/format.pysrc/datamodel_code_generator/config.py
🧬 Code graph analysis (4)
src/datamodel_code_generator/__main__.py (2)
src/datamodel_code_generator/enums.py (1)
UnionMode(192-196)src/datamodel_code_generator/parser/jsonschema.py (1)
model_rebuild(224-226)
tests/main/test_main_general.py (5)
src/datamodel_code_generator/config.py (1)
GenerateConfig(73-205)src/datamodel_code_generator/enums.py (3)
UnionMode(192-196)StrictTypes(199-206)DataModelType(48-56)src/datamodel_code_generator/model/base.py (1)
model_rebuild(200-207)src/datamodel_code_generator/types.py (1)
model_rebuild(310-317)src/datamodel_code_generator/__init__.py (1)
generate(451-1204)
tests/test_format.py (1)
tests/main/conftest.py (1)
output_dir(104-106)
src/datamodel_code_generator/__init__.py (2)
src/datamodel_code_generator/config.py (1)
GenerateConfig(73-205)src/datamodel_code_generator/enums.py (5)
GraphQLScope(155-158)InputFileType(35-45)DataModelType(48-56)ReuseScope(59-67)AllOfMergeMode(142-152)
🪛 Ruff (0.14.10)
src/datamodel_code_generator/__main__.py
785-785: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
786-786: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
789-789: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
791-791: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
src/datamodel_code_generator/config.py
6-6: Unused noqa directive (non-enabled: TC003)
Remove unused noqa directive
(RUF100)
src/datamodel_code_generator/__init__.py
606-606: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: 3.10 on Windows
- GitHub Check: 3.12 on Ubuntu
- GitHub Check: py312-pydantic1 on Ubuntu
- GitHub Check: 3.14 on macOS
- GitHub Check: 3.13 on macOS
- GitHub Check: 3.13 on Windows
- GitHub Check: 3.14 on Windows
- GitHub Check: 3.12 on Windows
- GitHub Check: 3.11 on Windows
- GitHub Check: benchmarks
- GitHub Check: Analyze (python)
🔇 Additional comments (8)
src/datamodel_code_generator/__main__.py (1)
779-808: Config modelmodel_rebuildhelper looks correct and well-scopedThe
_try_rebuild_model()helper and its use in_load_model_schema()cleanly handle the Pydantic v2 rebuild requirements forGenerateConfig/ParserConfig/ParseConfigwithout affecting arbitraryBaseModelsubclasses. The curated_types_namespace(Path, DataModel*, DataTypeManager, StrictTypes, UnionMode/Any) matches the config models’ annotations, and the fallback toAnyonUnionModeimport failure keeps v1-compatible behavior. I don’t see issues with this approach or its invocation guard onhasattr(obj, "model_rebuild").Also applies to: 889-891
tests/test_input_model.py (1)
609-617: New--input-modeltest forGenerateConfigcovers the config-schema path wellThis test nicely validates the
--input-model datamodel_code_generator.config:GenerateConfigflow under Pydantic v2, including TypedDict generation and preservation of callable field types. TheSKIP_PYDANTIC_V1marker is appropriate given the hard dependency onmodel_json_schema.tests/main/test_main_general.py (1)
9-10: Config-object tests correctly exercise the newgenerate(config=...)flowThe added
pydantic/GenerateConfigimports and the two@pytest.mark.skipif(pydantic.VERSION < "2.0.0")tests give good coverage of the new config-driven path:
test_generate_with_config_objectvalidates that core options (output_model_type, schema description, snake_case_field, field_constraints, extra_template_data) flow from aGenerateConfiginstance intogenerate()and affect the output as expected.test_generate_with_config_object_extra_template_data_overridechecks that an explicitextra_template_dataargument wins over the config’sextra_template_data, matching the merge logic ingenerate().- The explicit
GenerateConfig.model_rebuild(_types_namespace=...)before instantiation mirrors the runtime helper in__main__and ensures forward refs are resolved under Pydantic v2.Overall this is a solid, targeted verification of the public
configparameter ongenerate().Also applies to: 26-27, 1972-2019
src/datamodel_code_generator/format.py (1)
338-347: Ruff integration uses safe--fixoperations onlyThe Ruff calls in
apply_ruff_lint,apply_ruff_check_and_format, andformat_directoryall useruff check --fixwithout--unsafe-fixes, which applies only safe transformations. This is the correct approach for a library's code formatter, avoiding potentially destructive rewrites while still auto-fixing straightforward issues. The subprocess wiring (stdin/stdout, cwd, return-code handling) remains consistent across all invocation patterns.src/datamodel_code_generator/config.py (4)
41-71: Well-designed cross-version type compatibility.The conditional type aliases elegantly handle Pydantic v1/v2 differences: simple aliases for type-checking and v1, while v2 uses
AnnotatedwithWithJsonSchemato make callable fields serializable. Thex-python-typehints in the JSON schema provide clear documentation of the expected types.
73-206: Comprehensive configuration model with clean Pydantic v1/v2 compatibility.The
GenerateConfigmodel properly handles version differences with conditionalmodel_config(v2) vs. nestedConfigclass (v1). The nestedConfigclass includes a docstring, addressing the previous pipeline failure. The extensive field set comprehensively covers code generation options.
208-331: Parser configuration follows consistent patterns.The
ParserConfigmodel maintains the same clean v1/v2 compatibility approach asGenerateConfig. The type-parameterized fields (e.g.,data_model_type: type[DataModel]) leveragearbitrary_types_allowed=Trueto handle class types, and the nestedConfigclass includes proper documentation.
333-352: Streamlined parse configuration completes the config model trio.The
ParseConfigmodel maintains consistency with the other config models while focusing on a smaller set of parse-time options. The use offormat_(with trailing underscore) correctly avoids conflict with theformatkeyword.
# Conflicts: # src/datamodel_code_generator/__main__.py # tests/test_input_model.py
7d86135 to
ef68905
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/datamodel_code_generator/__init__.py (1)
588-770: Config propagation logic is correct.The extensive config merging correctly handles different parameter types with appropriate patterns:
- Boolean flags use
orfor False defaults- Optional parameters check
is None- Parameters with non-None defaults check equality with default value
- Special handling for
use_standard_collections,use_specialized_enum, anduse_union_operatorpreserves explicitFalsearguments while respecting configThe 200+ lines of repetitive merging code could benefit from abstraction (e.g., a helper function or dataclass-based merging), which would improve maintainability. However, the current implementation is functionally correct.
💡 Optional refactor idea
Consider extracting merge logic into a helper function that takes parameter metadata (name, default value, merge strategy) to reduce repetition. For example:
def _merge_config_param( param_name: str, param_value: Any, config_value: Any, default_value: Any, merge_strategy: Literal["or", "conditional", "special_bool"] = "conditional" ) -> Any: # Implement merge patterns based on strategy ...This would consolidate the patterns and make future parameter additions easier.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/datamodel_code_generator/__init__.pysrc/datamodel_code_generator/__main__.pytests/test_input_model.py
🚧 Files skipped from review as they are similar to previous changes (1)
- tests/test_input_model.py
🧰 Additional context used
🧬 Code graph analysis (2)
src/datamodel_code_generator/__main__.py (4)
src/datamodel_code_generator/model/base.py (3)
class_name(848-850)class_name(853-857)model_rebuild(200-207)src/datamodel_code_generator/model/pydantic_v2/types.py (1)
DataTypeManager(70-167)src/datamodel_code_generator/enums.py (2)
StrictTypes(213-220)UnionMode(192-196)src/datamodel_code_generator/parser/jsonschema.py (1)
model_rebuild(224-226)
src/datamodel_code_generator/__init__.py (2)
src/datamodel_code_generator/config.py (1)
GenerateConfig(73-205)src/datamodel_code_generator/enums.py (2)
InputFileType(35-45)DataModelType(48-56)
🪛 Ruff (0.14.10)
src/datamodel_code_generator/__main__.py
1079-1079: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
1080-1080: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
1083-1083: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
1085-1085: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
src/datamodel_code_generator/__init__.py
607-607: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: 3.13 on Windows
- GitHub Check: 3.12 on Windows
- GitHub Check: 3.11 on Windows
- GitHub Check: benchmarks
🔇 Additional comments (5)
src/datamodel_code_generator/__main__.py (2)
1185-1186: LGTM!The integration of
_try_rebuild_modelis appropriate here. Rebuilding the model before schema generation ensures forward references are properly resolved for config models while remaining backward-compatible with thehasattrguard.
1073-1102: Clean up unusednoqadirectives.The function logic looks good and correctly handles special rebuilding for config models. However, static analysis indicates unused
noqadirectives on lines 1079, 1080, 1083, and 1085.🔎 Proposed fix
if module in {"datamodel_code_generator.config", "config"} and class_name in config_classes: - from datamodel_code_generator.model.base import DataModel, DataModelFieldBase # noqa: PLC0415 - from datamodel_code_generator.types import DataTypeManager, StrictTypes # noqa: PLC0415 + from datamodel_code_generator.model.base import DataModel, DataModelFieldBase + from datamodel_code_generator.types import DataTypeManager, StrictTypes try: - from datamodel_code_generator.model.pydantic_v2 import UnionMode # noqa: PLC0415 + from datamodel_code_generator.model.pydantic_v2 import UnionMode except ImportError: # pragma: no cover - from typing import Any # noqa: PLC0415 + from typing import Any runtime_union_mode = Any⛔ Skipped due to learnings
Learnt from: koxudaxi Repo: koxudaxi/datamodel-code-generator PR: 2799 File: src/datamodel_code_generator/model/pydantic/__init__.py:43-43 Timestamp: 2025-12-25T09:22:14.661Z Learning: In datamodel-code-generator project, defensive `# noqa: PLC0415` directives should be kept on lazy imports (imports inside functions/methods) even when Ruff reports them as unused via RUF100, to prepare for potential future Ruff configuration changes that might enable the import-outside-top-level rule.src/datamodel_code_generator/__init__.py (3)
64-64: LGTM!Adding
GenerateConfigtoTYPE_CHECKINGimports is the correct pattern for type hints, avoiding runtime circular import issues while providing proper type information.
517-517: LGTM!Removing the
noqa: TC001comment is appropriate now thatgraphql_scopesis properly integrated with the config propagation logic and is actually used (line 679).
607-607: Remove unusednoqadirective.Static analysis indicates the
noqa: PLC0415directive on this line is not needed.🔎 Proposed fix
- from collections import defaultdict as _defaultdict # noqa: PLC0415 + from collections import defaultdict as _defaultdict⛔ Skipped due to learnings
Learnt from: koxudaxi Repo: koxudaxi/datamodel-code-generator PR: 2799 File: src/datamodel_code_generator/model/pydantic/__init__.py:43-43 Timestamp: 2025-12-25T09:22:14.661Z Learning: In datamodel-code-generator project, defensive `# noqa: PLC0415` directives should be kept on lazy imports (imports inside functions/methods) even when Ruff reports them as unused via RUF100, to prepare for potential future Ruff configuration changes that might enable the import-outside-top-level rule.Learnt from: koxudaxi Repo: koxudaxi/datamodel-code-generator PR: 2681 File: tests/cli_doc/test_cli_doc_coverage.py:82-82 Timestamp: 2025-12-18T13:43:16.235Z Learning: In datamodel-code-generator project, Ruff preview mode is enabled via `lint.preview = true` in pyproject.toml. This enables preview rules like PLR6301 (no-self-use), so `noqa: PLR6301` directives are necessary and should not be removed even if RUF100 suggests they are unused.
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
pyproject.tomlsrc/datamodel_code_generator/_types/generate_config_dict.pysrc/datamodel_code_generator/_types/parser_config_dict.py
🧰 Additional context used
🧬 Code graph analysis (1)
src/datamodel_code_generator/_types/parser_config_dict.py (4)
src/datamodel_code_generator/enums.py (8)
AllOfMergeMode(142-152)CollapseRootModelsNameStrategy(131-139)FieldTypeCollisionStrategy(105-113)NamingStrategy(116-128)ReadOnlyWriteOnlyModelType(161-169)ReuseScope(59-67)StrictTypes(213-220)TargetPydanticVersion(181-189)src/datamodel_code_generator/format.py (1)
PythonVersion(68-140)src/datamodel_code_generator/parser/__init__.py (2)
LiteralType(20-25)DefaultPutDict(28-47)src/datamodel_code_generator/_types/generate_config_dict.py (1)
DataclassArguments(36-46)
🪛 Ruff (0.14.10)
src/datamodel_code_generator/_types/parser_config_dict.py
42-42: Undefined name datamodel_code_generator
(F821)
43-43: Undefined name datamodel_code_generator
(F821)
44-44: Undefined name datamodel_code_generator
(F821)
45-45: Undefined name datamodel_code_generator
(F821)
87-87: Undefined name DefaultPutDict
(F821)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (15)
- GitHub Check: build-deploy
- GitHub Check: py312-isort7 on Ubuntu
- GitHub Check: py312-black23 on Ubuntu
- GitHub Check: py312-pydantic1 on Ubuntu
- GitHub Check: py312-isort6 on Ubuntu
- GitHub Check: py312-black22 on Ubuntu
- GitHub Check: 3.11 on Windows
- GitHub Check: 3.13 on Ubuntu
- GitHub Check: py312-black24 on Ubuntu
- GitHub Check: 3.10 on Windows
- GitHub Check: 3.12 on Windows
- GitHub Check: 3.13 on Windows
- GitHub Check: benchmarks
- GitHub Check: 3.14 on Windows
- GitHub Check: Analyze (python)
🔇 Additional comments (6)
src/datamodel_code_generator/_types/parser_config_dict.py (1)
28-38: LGTM!The DataclassArguments TypedDict is properly defined with all standard dataclass parameters correctly typed as optional booleans.
pyproject.toml (2)
247-247: LGTM! Coverage exclusion for generated types is appropriate.Excluding the
_typesdirectory from coverage is correct since it contains auto-generated TypedDict definitions that don't require test coverage.
262-287: Input models are properly defined. All three Pydantic models referenced in the profiles—GenerateConfig(line 73),ParserConfig(line 208), andParseConfig(line 333)—exist insrc/datamodel_code_generator/config.pyand are correctly structured as BaseModel subclasses with Pydantic v2/v1 compatibility.src/datamodel_code_generator/_types/generate_config_dict.py (3)
1-33: LGTM! Import structure follows best practices.The use of
TYPE_CHECKINGguards for type-only imports is excellent for minimizing runtime overhead. The imports are well-organized andNotRequiredfromtyping_extensionsensures compatibility across Python versions.
36-46: LGTM! DataclassArguments TypedDict accurately mirrors dataclass parameters.The TypedDict correctly represents all standard
dataclasses.dataclassdecorator parameters with appropriateNotRequired[bool]types.
49-169: LGTM! GenerateConfigDict provides comprehensive type-safe configuration.The TypedDict correctly exposes a broad configuration surface with 120 fields covering all aspects of code generation. The consistent use of
NotRequiredallows partial configuration, which is appropriate for this use case.Since this is auto-generated from the Pydantic
GenerateConfigmodel, the types should stay in sync with the source model.
Add tests to ensure Config classes and generated TypedDicts remain in sync: - Type matching tests for ParserConfigDict and ParseConfigDict - Default value matching test for GenerateConfig vs generate() signature - Runtime compatibility test verifying generate() produces identical output
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
tests/main/test_public_api_signature_baseline.py
🧰 Additional context used
🪛 GitHub Actions: Lint
tests/main/test_public_api_signature_baseline.py
[error] 449-449: Ruff: N806 Variable UnionMode in function should be lowercase
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: 3.11 on Ubuntu
- GitHub Check: 3.11 on Windows
- GitHub Check: py312-black24 on Ubuntu
- GitHub Check: py312-isort7 on Ubuntu
- GitHub Check: 3.12 on Windows
- GitHub Check: 3.10 on Windows
- GitHub Check: py312-pydantic1 on Ubuntu
- GitHub Check: 3.13 on Windows
- GitHub Check: 3.14 on Windows
- GitHub Check: Analyze (python)
- GitHub Check: benchmarks
🔇 Additional comments (7)
tests/main/test_public_api_signature_baseline.py (7)
8-9: LGTM!The pytest import and GenerateConfig type import are appropriate additions for the expanded test suite.
Also applies to: 39-39
51-51: LGTM!The addition of the optional
configparameter to the baseline signature correctly reflects the new config-driven generation pathway.
331-355: LGTM!The type normalization helper correctly handles the various type representation differences (ForwardRef, NotRequired, module prefixes, etc.) needed for cross-dictionary comparison.
321-328: LGTM!The field alignment tests correctly validate that Config classes and their corresponding ConfigDict TypedDicts have matching field names using set comparison.
Also applies to: 371-378, 381-388
358-368: LGTM!The type alignment tests correctly validate that field types match between Config classes and ConfigDict TypedDicts by normalizing and comparing type annotations.
Also applies to: 391-401, 404-414
417-438: LGTM!The default value alignment test correctly validates that GenerateConfig defaults match the generate() signature, properly handling both required parameters and those with explicit defaults.
441-448: Well-structured functional equivalence test.The test correctly validates that config-driven and kwargs-driven generation produce identical output, with appropriate version checks and conditional model rebuilding for Pydantic v2.
Also applies to: 459-483
- Update GenerateConfig and ParserConfig to use defaultdict with Annotated/WithJsonSchema for Pydantic compatibility - Regenerate TypedDicts with proper defaultdict type and import - Update test normalization to handle Annotated types and collections prefix
0f26edb to
78e492e
Compare
Replace complex _normalize_type_str function and detailed type comparison with simpler field count checks. The integration test test_generate_with_config_produces_same_result_as_kwargs validates that Config classes work correctly at runtime, making detailed type string comparison unnecessary. Also fix lint errors: - N813: Restructure UnionMode import to avoid CamelCase-to-lowercase alias - I001: Fix import sorting order 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Implement _normalize_type function using typing APIs (get_origin, get_args) to normalize types for comparison between Config classes and generated TypedDicts. Handles: - Union types with sorted components - Annotated and NotRequired wrappers - ForwardRef string parsing - Callable with list args - Module prefix removal (collections.abc, typing, etc.) Tests now verify: 1. Field names match 2. Field types match (normalized) 3. Default values match 4. Integration test validates runtime behavior 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Breaking Change AnalysisResult: No breaking changes detected Reasoning: This PR is purely additive - it adds a new optional This analysis was performed by Claude Code Action |
…onfig (#2844) * Add GenerateConfig class and auto-generate TypedDicts for type-safe config * Add --unsafe-fixes to ruff-check formatter * Skip config-types hook in lint workflow * Fix UnionType serialization and skip tox-dependent hooks in lint CI * Revert --unsafe-fixes and exclude _types from pre-commit ruff * Regenerate config types after merging main * Remove UnionType handling (should be separate PR) * Pin Python 3.14 for config-types CI * Remove unused _from_generate_config methods * Fix use_standard_collections merge logic * Fix coverage omit pattern for _types directory * Regenerate TypedDicts after merging set/frozenset fix * Add test for extra_template_data override and coverage pragmas * Restore --unsafe-fixes flag in ruff commands * Restore _try_rebuild_model and test_input_model_config_class after merge * Use --input-model-ref-strategy to simplify config type generation * Regenerate config types with improved reuse-foreign strategy * Remove WithJsonSchema annotations - automatic handling works * Add tests to ensure Config and ConfigDict fields/types match * Add comprehensive Config/TypedDict compatibility tests Add tests to ensure Config classes and generated TypedDicts remain in sync: - Type matching tests for ParserConfigDict and ParseConfigDict - Default value matching test for GenerateConfig vs generate() signature - Runtime compatibility test verifying generate() produces identical output * Use defaultdict for extra_template_data to match generate() signature - Update GenerateConfig and ParserConfig to use defaultdict with Annotated/WithJsonSchema for Pydantic compatibility - Regenerate TypedDicts with proper defaultdict type and import - Update test normalization to handle Annotated types and collections prefix * Fix N806 lint: rename UnionMode variable to lowercase * Simplify type comparison tests for Config/TypedDict Replace complex _normalize_type_str function and detailed type comparison with simpler field count checks. The integration test test_generate_with_config_produces_same_result_as_kwargs validates that Config classes work correctly at runtime, making detailed type string comparison unnecessary. Also fix lint errors: - N813: Restructure UnionMode import to avoid CamelCase-to-lowercase alias - I001: Fix import sorting order * Add type comparison tests for Config/TypedDict equivalence Implement _normalize_type function using typing APIs (get_origin, get_args) to normalize types for comparison between Config classes and generated TypedDicts. Handles: - Union types with sorted components - Annotated and NotRequired wrappers - ForwardRef string parsing - Callable with list args - Module prefix removal (collections.abc, typing, etc.) Tests now verify: 1. Field names match 2. Field types match (normalized) 3. Default values match 4. Integration test validates runtime behavior * Fix formatting * Skip Config/TypedDict tests on Pydantic v1 * Add default value tests for ParserConfig and ParseConfig * Use @PYDANTIC_V2_SKIP decorator for pydantic v2 tests * Fix type normalization for types.UnionType (Python 3.10+)
Summary by CodeRabbit
New Features
Chores
Tests
✏️ Tip: You can customize this high-level summary in your review settings.