-
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
Open
0xCUB3
wants to merge
13
commits into
generative-computing:main
Choose a base branch
from
0xCUB3:feat/import-repair
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
0xCUB3
commented
Dec 4, 2025
Author
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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