Summary
Fixes the class generator's user_code_parser.py to recognize the new MissingRequiredArgumentError import location (ocp_resources.exceptions) as a template import, preventing duplicate imports when regenerating resource classes with --overwrite.
Problem / Motivation
When regenerating resource files (e.g., class-generator --kind X --overwrite), the parse_user_code_from_file() function checks imports against a hardcoded template_imports set to distinguish template-generated imports from user-added imports. The new correct import pattern from ocp_resources.exceptions import MissingRequiredArgumentError (from the Jinja2 template) is missing from this set, causing the parser to treat it as user-added code and preserve it — resulting in duplicate imports alongside the freshly rendered template imports.
This was observed in PR #2647 where CodeRabbit flagged Ruff F811 (redefinition of unused imports).
Root Cause
class_generator/parsers/user_code_parser.py line 59-65: the template_imports set is missing:
"from ocp_resources.exceptions import MissingRequiredArgumentError"
Requirements
- Add
from ocp_resources.exceptions import MissingRequiredArgumentError to template_imports in user_code_parser.py
- Update related tests in
test_user_code_parser.py
- Verify all tests pass
Deliverables
Notes
This is a one-line fix to the template_imports set, plus corresponding test updates.