Refactor: Use model_validate/parse_obj for Parser config initialization#2880
Refactor: Use model_validate/parse_obj for Parser config initialization#2880
Conversation
📝 WalkthroughWalkthroughThe PR refactors the Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
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-2880.datamodel-code-generator.pages.dev |
CodSpeed Performance ReportMerging #2880 will not alter performanceComparing
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/datamodel_code_generator/__init__.py (1)
605-660: Consider removing unusednoqadirectives.Static analysis indicates that several
# noqa: PLC0415directives in this block (lines 606, 614, 625, 641, 656) are unused because thePLC0415rule is not enabled. If the rule is intentionally disabled project-wide, these directives can be safely removed to reduce noise.🔎 Proposed cleanup
- import json # noqa: PLC0415 + import json import csv # noqa: PLC0415 - import csv # noqa: PLC0415 + import csv - import io # noqa: PLC0415 + import io - import ast # noqa: PLC0415 + import ast - from genson import SchemaBuilder # noqa: PLC0415 + from genson import SchemaBuilder
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/datamodel_code_generator/__init__.py
🧰 Additional context used
🧬 Code graph analysis (1)
src/datamodel_code_generator/__init__.py (9)
src/datamodel_code_generator/_types/graphql_parser_config_dict.py (1)
GraphQLParserConfigDict(33-146)src/datamodel_code_generator/_types/openapi_parser_config_dict.py (1)
OpenAPIParserConfigDict(34-148)src/datamodel_code_generator/_types/parser_config_dict.py (1)
ParserConfigDict(33-144)src/datamodel_code_generator/_types/generate_config_dict.py (1)
GenerateConfigDict(39-160)src/datamodel_code_generator/config.py (5)
GenerateConfig(65-198)ParserConfig(201-324)GraphQLParserConfig(327-331)JSONSchemaParserConfig(334-335)OpenAPIParserConfig(338-343)src/datamodel_code_generator/util.py (2)
is_pydantic_v2(52-57)model_validate(261-265)src/datamodel_code_generator/parser/jsonschema.py (2)
parse_obj(3450-3495)JsonSchemaParser(526-3646)src/datamodel_code_generator/parser/openapi.py (1)
OpenAPIParser(164-767)src/datamodel_code_generator/parser/graphql.py (1)
GraphQLParser(62-508)
🪛 Ruff (0.14.10)
src/datamodel_code_generator/__init__.py
606-606: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
614-614: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
625-625: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
641-641: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
656-656: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
691-691: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
731-731: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
742-742: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
752-752: 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). (14)
- GitHub Check: py312-isort7 on Ubuntu
- GitHub Check: py312-isort5 on Ubuntu
- GitHub Check: py312-black22 on Ubuntu
- GitHub Check: 3.12 on Windows
- GitHub Check: 3.10 on Ubuntu
- GitHub Check: 3.10 on macOS
- GitHub Check: 3.11 on Windows
- GitHub Check: py312-isort6 on Ubuntu
- GitHub Check: 3.10 on Windows
- GitHub Check: 3.12 on Ubuntu
- GitHub Check: 3.14 on Windows
- GitHub Check: 3.13 on Windows
- GitHub Check: benchmarks
- GitHub Check: Analyze (python)
🔇 Additional comments (5)
src/datamodel_code_generator/__init__.py (5)
64-72: LGTM!The new TYPE_CHECKING imports and the
_ConfigTTypeVar bound toParserConfigare correctly defined for supporting the generic_create_parser_confighelper.
697-728: LGTM!The
additional_optionsdictionary correctly computes conditional defaults fortarget_datetime_class,enum_field_as_literal, andset_default_enum_memberbased on the input file type and output model type.
730-755: LGTM!The parser instantiation is cleanly refactored to use
_create_parser_configfor all three parser types (OpenAPI, GraphQL, JSONSchema). The pattern of merging commonadditional_optionswith parser-specific options via spread operator is appropriate.
691-695: LGTM!The parser config class imports are correctly placed at the point of use within the
generate()function.
452-470: No issues found. Theextra="ignore"parameter is a valid argument tomodel_validate()in Pydantic v2. According to the official Pydantic v2 documentation,model_validate()accepts theextraparameter, which controls how extra fields are handled during validation (allow/ignore/forbid) and overrides the model-level configuration for that validation call.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2880 +/- ##
=======================================
Coverage 99.38% 99.38%
=======================================
Files 91 91
Lines 15643 15649 +6
Branches 1848 1848
=======================================
+ Hits 15547 15553 +6
Misses 50 50
Partials 46 46
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:
|
|
🎉 Released in 0.51.0 This PR is now available in the latest release. See the release notes for details. |
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.