fix: add exceptions import to template_imports in user_code_parser#2657
fix: add exceptions import to template_imports in user_code_parser#2657
Conversation
The template_imports set in user_code_parser.py was missing "from ocp_resources.exceptions import MissingRequiredArgumentError", causing duplicate imports when regenerating resource files with --overwrite. Closes #2656
|
No actionable comments were generated in the recent review. 🎉 WalkthroughThis PR adds the Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes 🚥 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 |
|
Report bugs in Issues Welcome! 🎉This pull request will be automatically processed with the following features: 🔄 Automatic Actions
📋 Available CommandsPR Status Management
Review & Approval
Testing & Validation
Cherry-pick Operations
Label Management
✅ Merge RequirementsThis PR will be automatically approved when the following conditions are met:
📊 Review ProcessApprovers and ReviewersApprovers:
Reviewers:
Available Labels
💡 Tips
For more information, please refer to the project documentation or contact the maintainers. |
|
/lgtm |
|
/approve |
What this PR does
Adds
from ocp_resources.exceptions import MissingRequiredArgumentErrorto thetemplate_importsset inclass_generator/parsers/user_code_parser.py.Why we need it
The Jinja2 template (
class_generator_template.j2) generates:But the
template_importsset inuser_code_parser.pydidn't include this pattern. When regenerating resource files with--overwrite, the parser treated this template-generated import as user-added code, preserving it — which then duplicated alongside the freshly rendered template imports.This was observed in #2647 where CodeRabbit flagged Ruff F811 (redefinition of unused imports).
Which issue(s) this PR fixes
Closes #2656
Test plan
test_parse_file_with_exceptions_importto verify the new import pattern is recognized as a template importtest_user_code_parser.pycontinue to passSummary by CodeRabbit
Bug Fixes
Tests