-
Notifications
You must be signed in to change notification settings - Fork 9
feat: Import Repair #11
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
feat: Import Repair #11
Conversation
Add common_aliases.py with ~100+ common Python import aliases organized by category (data science, ML, stdlib, web, testing, etc.) and module relocation patterns for sklearn, tensorflow, torch, scipy.
Add import_resolution.py with: - Error parsing for ModuleNotFoundError, ImportError, NameError, AttributeError - AST-based undefined name detection for static analysis - Resolution functions with fuzzy matching support - Integration with common_aliases database
Add import_repair.py with: - PythonImportRepair Requirement class - Static analysis mode (default) using AST - Execution-based mode with subprocess or sandbox - Formatted repair feedback for RepairTemplateStrategy
Test coverage for: - Error parsing (ModuleNotFoundError, ImportError, NameError, AttributeError) - AST-based undefined name detection - Import resolution and suggestions - Common aliases database - Module availability checking
Change from absolute to relative import for statute_data module.
Add local implementation of extract_python_code to avoid dependency on mellea version that may not export it.
…code Add tests for: - extract_python_code with various markdown formats - PythonImportRepair with mocked mellea Context - Validation of valid code, missing imports, syntax errors, unavailable modules
- Add lambda parameter detection to AST undefined name finder - Support capital P in Python code block tags - Add tests for lambda params and capital Python tags
- Handle Python 3.10+ match statement case pattern bindings - Support ```py and ```python3 code block tags - Clean up unnecessary comments in AST walker - Add tests for new functionality
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.
can remove if not necessary. I know mellea proper has this but it doesn't exist here.
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.
Thanks for adding.
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.
Thanks for adding.
Adds
PythonImportRepairrequirement for detecting and suggesting fixes for missing/incorrect imports in LLM-generated Python code.Detection modes:
allow_unsafe_execution=True): runs code and parses runtime errors. MatchesPythonExecutionReqinterface (i.e. when code execution is enabled, import validation uses execution too)Features:
ModuleNotFoundError,ImportError,NameError,AttributeError. Any I'm missing?rapidfuzzRepairTemplateStrategyviaValidationResult.reasonUsage:
Files:
mellea_contribs/reqlib/common_aliases.py- Alias databasemellea_contribs/reqlib/import_resolution.py- Error parsing and resolutionmellea_contribs/reqlib/import_repair.py-PythonImportRepairclasstest/test_import_repair.py- new testsDependencies:
rapidfuzz- Fast fuzzy matching for misspelled modules. Chosen overfuzzywuzzy(10x faster, no GPL licensing issues via python-Levenshtein, though way better name :) ) anddifflib(faster, better ranking algorithm).My tests