-
-
Notifications
You must be signed in to change notification settings - Fork 424
fix: move UnionMode import outside TYPE_CHECKING for Pydantic runtime… #2950
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
… access The UnionMode type is used in GenerateConfig.union_mode field annotation. Pydantic needs to access this type at runtime for model validation, but it was only imported inside TYPE_CHECKING block, causing: PydanticUserError: GenerateConfig is not fully defined; you should define UnionMode, then call GenerateConfig.model_rebuild(). This follows the same pattern as other runtime-required imports in this file (Path, DataModel, DataModelFieldBase, etc.) which have noqa: TC001 comments.
📝 WalkthroughWalkthroughUnionMode is now imported at module scope from Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧠 Learnings (2)📓 Common learnings📚 Learning: 2025-12-25T09:23:08.506ZApplied to files:
🧬 Code graph analysis (1)src/datamodel_code_generator/config.py (1)
🪛 Ruff (0.14.10)src/datamodel_code_generator/config.py47-47: Unused Remove unused (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). (2)
🔇 Additional comments (2)
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a Pydantic runtime validation error by moving the UnionMode import outside the TYPE_CHECKING block. The type annotation is used in the GenerateConfig.union_mode field and must be accessible at runtime for Pydantic model validation.
Key changes:
- Moved
UnionModeimport fromTYPE_CHECKINGblock to runtime imports - Added
noqa: TC001comment to suppress type-checking linter warning, consistent with other runtime-required imports
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Alternatively this here in pyproject :) [tool.ruff.lint.flake8-type-checking]
runtime-evaluated-base-classes = ["pydantic.BaseModel"] |
CodSpeed Performance ReportMerging this PR will degrade performance by 15.48%Comparing
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | WallTime | test_perf_duplicate_names |
842.7 ms | 988.2 ms | -14.73% |
| ❌ | WallTime | test_perf_deep_nested |
5.2 s | 5.9 s | -12.83% |
| ❌ | WallTime | test_perf_kubernetes_style_pydantic_v2 |
2.2 s | 2.6 s | -15.32% |
| ❌ | WallTime | test_perf_aws_style_openapi_pydantic_v2 |
1.7 s | 1.9 s | -12.54% |
| ❌ | WallTime | test_perf_graphql_style_pydantic_v2 |
705 ms | 809.8 ms | -12.94% |
| ❌ | WallTime | test_perf_complex_refs |
1.8 s | 2 s | -12.07% |
| ❌ | WallTime | test_perf_multiple_files_input |
3.2 s | 3.8 s | -15.48% |
| ❌ | WallTime | test_perf_stripe_style_pydantic_v2 |
1.7 s | 1.9 s | -14% |
| ❌ | WallTime | test_perf_all_options_enabled |
5.8 s | 6.7 s | -13.55% |
| ❌ | WallTime | test_perf_openapi_large |
2.5 s | 2.9 s | -14.3% |
| ❌ | WallTime | test_perf_large_models_pydantic_v2 |
3.1 s | 3.6 s | -15.14% |
Footnotes
-
98 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2950 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 94 94
Lines 17716 17717 +1
Branches 2037 2037
=========================================
+ Hits 17716 17717 +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:
|
… access
The UnionMode type is used in GenerateConfig.union_mode field annotation. Pydantic needs to access this type at runtime for model validation, but it was only imported inside TYPE_CHECKING block, causing:
PydanticUserError: GenerateConfig is not fully defined; you should define UnionMode, then call GenerateConfig.model_rebuild().
This follows the same pattern as other runtime-required imports in this file (Path, DataModel, DataModelFieldBase, etc.) which have noqa: TC001 comments.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.