Add ryaml as optional YAML backend for faster parsing#3055
Conversation
Generated by GitHub Actions
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds ryaml as an optional YAML parser and runtime detection/utilities to prefer ryaml when available; load_yaml and infer_input_type now use the detected backend and parse-error types. Also updates several documentation examples to replace lambda-based Field default_factories with direct defaults and validate_default=True, and adds tests for YAML backend behavior. Changes
Sequence DiagramsequenceDiagram
participant Caller as Caller
participant Loader as load_yaml
participant Detector as get_yaml_backend
participant Ryaml as ryaml
participant PyYAML as PyYAML
Caller->>Loader: load_yaml(input)
Loader->>Detector: get_yaml_backend()
Detector-->>Loader: "ryaml" or "pyyaml"
alt backend == "ryaml"
Loader->>Ryaml: ryaml.loads(input)
Ryaml-->>Loader: parsed_data
else backend == "pyyaml"
Loader->>PyYAML: yaml.load(input, SafeLoader)
PyYAML-->>Loader: parsed_data
end
Loader-->>Caller: parsed_data
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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-3055.datamodel-code-generator.pages.dev |
Merging this PR will not alter performance
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3055 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 85 86 +1
Lines 17911 18011 +100
Branches 2074 2075 +1
==========================================
+ Hits 17911 18011 +100
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:
|
There was a problem hiding this comment.
🧹 Nitpick comments (2)
pyproject.toml (1)
63-65: Includeryamlin theallextra to keep extras behavior consistent.Line 63 adds a new optional feature, but
datamodel-code-generator[all]won’t include it unlessoptional-dependencies.allis also updated.Suggested patch
optional-dependencies.all = [ "datamodel-code-generator[debug]", "datamodel-code-generator[graphql]", "datamodel-code-generator[http]", + "datamodel-code-generator[ryaml]", "datamodel-code-generator[ruff]", "datamodel-code-generator[validation]", "datamodel-code-generator[watch]", ]🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pyproject.toml` around lines 63 - 65, The new optional extra optional-dependencies.ryaml (ryaml>=0.4) was added but not included in the aggregate optional-dependencies.all extra; update the optional-dependencies.all list in pyproject.toml to include "ryaml" so that installing datamodel-code-generator[all] pulls this new optional dependency; locate the optional-dependencies.all definition and append "ryaml" (matching the extra name) to that list.tests/test_yaml_backend.py (1)
64-97: Optional cleanup: parameterize the duplicated backend/input tests.The four
load_yamltests share the same structure;pytest.mark.parametrizewould reduce duplication and future maintenance drift.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/test_yaml_backend.py` around lines 64 - 97, Refactor the four tests in TestLoadYaml to a single parameterized test using pytest.mark.parametrize over two axes: backend availability (e.g., a tuple with ("ryaml_missing", None, expected_calls) and ("ryaml_present", mock_ryaml, expected_calls)) and input type (string vs io.StringIO); inside the test, inject sys.modules via patch.dict("sys.modules", {"ryaml": backend_mock}), prepare the input value (raw string or stream), call load_yaml(input), and assert both the returned dict and whether mock_ryaml.loads was called with the expected string when a mock is provided; reference TestLoadYaml and load_yaml to locate the code to replace.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@pyproject.toml`:
- Around line 63-65: The new optional extra optional-dependencies.ryaml
(ryaml>=0.4) was added but not included in the aggregate
optional-dependencies.all extra; update the optional-dependencies.all list in
pyproject.toml to include "ryaml" so that installing
datamodel-code-generator[all] pulls this new optional dependency; locate the
optional-dependencies.all definition and append "ryaml" (matching the extra
name) to that list.
In `@tests/test_yaml_backend.py`:
- Around line 64-97: Refactor the four tests in TestLoadYaml to a single
parameterized test using pytest.mark.parametrize over two axes: backend
availability (e.g., a tuple with ("ryaml_missing", None, expected_calls) and
("ryaml_present", mock_ryaml, expected_calls)) and input type (string vs
io.StringIO); inside the test, inject sys.modules via patch.dict("sys.modules",
{"ryaml": backend_mock}), prepare the input value (raw string or stream), call
load_yaml(input), and assert both the returned dict and whether mock_ryaml.loads
was called with the expected string when a mock is provided; reference
TestLoadYaml and load_yaml to locate the code to replace.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: c1d53ea8-d94d-4d8a-851f-e7555a4307fa
⛔ Files ignored due to path filters (2)
docs/llms-full.txtis excluded by none and included by noneuv.lockis excluded by!**/*.lock,!**/*.lockand included by none
📒 Files selected for processing (8)
docs/cli-reference/field-customization.mddocs/cli-reference/model-customization.mddocs/cli-reference/template-customization.mddocs/cli-reference/typing-customization.mdpyproject.tomlsrc/datamodel_code_generator/__init__.pysrc/datamodel_code_generator/util.pytests/test_yaml_backend.py
Breaking Change AnalysisResult: No breaking changes detected Reasoning: PR #3055 adds ryaml as an optional YAML backend for faster parsing. This is purely additive - users must explicitly install the optional dependency with This analysis was performed by Claude Code Action |
|
🎉 Released in 0.56.0 This PR is now available in the latest release. See the release notes for details. |
Fixes: #2785
Summary by CodeRabbit
New Features
Documentation
Tests