Skip default_factory wrapping for non-callable type aliases#3012
Skip default_factory wrapping for non-callable type aliases#3012koxudaxi merged 4 commits intokoxudaxi:mainfrom
Conversation
…udaxi#3009) When --use-type-alias + --use-annotated + --enum-field-as-literal all are combined, the generator produced `default_factory=lambda: Mode('default')` where Mode is a PEP 695 type alias (not callable). Add a TypeAliasBase guard in __wrap_root_model_default_values to skip wrapping for type aliases. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughRefines the guard that wraps root-model default values: wrapping now occurs only when Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
Merging this PR will not alter performance
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/datamodel_code_generator/parser/base.py`:
- Line 2161: The long conditional needs to be reformatted to satisfy
ruff-format: break the if condition into a parenthesized multi-line expression
and align each clause on its own line so the expression is wrapped and
PEP8-friendly (target the if in parser/base.py that references
data_type.reference, data_type.reference.source, self.data_model_root_type, and
TypeAliasBase); update the if at the start of the conditional to use parentheses
and line breaks for each isinstance check and the negation, then run the
project's formatter (ruff/black) to commit the formatted change so CI passes.
ℹ️ Review info
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
tests/data/jsonschema/enum_literal_type_alias_default.jsonis excluded by!tests/data/**/*.jsonand included by none
📒 Files selected for processing (3)
src/datamodel_code_generator/parser/base.pytests/data/expected/main/jsonschema/enum_literal_type_alias_default.pytests/main/jsonschema/test_main_jsonschema.py
Skip the enum_literal_type_alias_default test on black < 23 since PEP 695 `type` statement syntax is unsupported. Reformat long conditional in parser/base.py to satisfy ruff line-length. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3012 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 94 94
Lines 18130 18133 +3
Branches 2099 2099
=========================================
+ Hits 18130 18133 +3
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:
|
Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
I am not sure how my code might cause performance regression. According to CodSpeed report, the regression seems to be coming from black formatting |
Breaking Change AnalysisResult: No breaking changes detected Reasoning: This PR is a bug fix, not a breaking change. The previous behavior generated invalid Python code (wrapping type alias defaults in default_factory with a lambda that tries to call the type alias, which is not callable). The fix produces correct code. Breaking changes involve changing behavior that previously worked correctly - this PR corrects behavior that was always broken, making it a pure bug fix. This analysis was performed by Claude Code Action |
|
🎉 Released in 0.54.1 This PR is now available in the latest release. See the release notes for details. |
Fix #3009
Summary by CodeRabbit
Bug Fixes
Tests