AutoFix is a command-line tool that accelerates debugging and test failure triage by combining AST-based static analysis and runtime traceback parsing. It scans your Python project, indexes all functions/classes for O(1) lookups, parses Pytest failures, and applies pattern-matching logic to automatically suggest likely fixes.
-
AST-based Symbol Indexing
Parses all.pyfiles to build an in-memory index of functions, classes, methods, and attributes for O(1) lookups. -
Runtime Traceback Parsing
Extracts structured frame data and exception summaries from rawpytestoutput or plain Python tracebacks. -
AI-like Suggestion Engine
Applies heuristic and pattern-based rules to detect common issues and suggest targeted fixes. -
Automatic Pytest Integration
Runspytest, captures failures, parses tracebacks, and ranks possible solutions—all in one command. -
Extensible Rule Engine
Add your own fix patterns for custom project needs. Rules are modular and isolated for easy extension. -
Human & Machine Readable Reports
Outputs clean human-readable text reports or structured JSON for integration with CI/CD dashboards.
You can clone and use directly:
git clone https://github.com/yourusername/autofix.git
cd autofix
python3 autofix.py --helpNo dependencies beyond Python’s standard library (requires Python 3.8+). You only need Pytest installed and accessible on your PATH.
Build an AST index for your project:
python autofix.py analyze src/ tests/This scans your code and prints how many functions, classes, and modules were indexed.
Run tests, parse traceback output, and get fix suggestions in one go:
python autofix.py run --pytest-args "-q -x" src/ tests/Example output:
================================================================================
Failure #1: NameError: name 'DataFram' is not defined
Frames:
• src/utils/data_loader.py:22 in load_dataset
Suggestions (ranked):
- Add missing import for 'DataFrame' [score=0.90]
fix: from pandas import DataFrame
You can also export structured results for machine consumption:
python autofix.py run --json results.json src/ tests/If you have saved a traceback or pytest output to a file (e.g., tb.txt):
python autofix.py suggest --traceback tb.txt src/Export JSON output:
python autofix.py suggest --traceback tb.txt src/ --json suggestions.jsonAutoFix walks your source tree and parses .py files using the ast module. It collects:
- Function and method signatures (args, defaults, keywords)
- Class names, attributes, and methods
- Module-level imports
These are stored in dictionaries for O(1) lookups, enabling near-instant fix suggestions.
AutoFix reads your pytest output or saved traceback text and extracts:
- Frame info: file, line number, function name
- Exception type & message
Each rule is a small heuristic that matches specific error patterns. For example:
| Rule Name | Target Error | Suggestion |
|---|---|---|
NameErrorMissingImport |
NameError |
Suggests imports for known symbols |
AttributeErrorMaybeTypo |
AttributeError |
Detects likely typos (via Levenshtein distance) |
TypeErrorWrongArity |
TypeError |
Points to mismatched function signatures |
ImportErrorModule |
ImportError |
Proposes pip install or relative import fix |
KeyErrorDict |
KeyError |
Recommends .get() or membership checks |
IndexErrorBound |
IndexError |
Suggests bound checking |
AssertionErrorEquality |
AssertionError |
Reminds to use pytest.approx for floats |
-
Run your tests:
pytest -q --tb=short > tb.txt -
Feed traceback into AutoFix:
python autofix.py suggest -t tb.txt src/
-
Get clear, actionable suggestions in seconds.
+------------------------+
| AutoFix CLI (argparse) |
+------------------------+
|
v
+-----------------------+
| SymbolIndex (AST) |
| → functions/classes |
+-----------------------+
|
v
+-----------------------+
| TracebackParser |
| → extract frames & errors |
+-----------------------+
|
v
+-----------------------+
| RuleEngine |
| → apply fix rules |
+-----------------------+
|
v
+-----------------------+
| Reporter (text/json) |
+-----------------------+
You can add new rules easily:
def rule_custom(self, tb: ParsedTraceback):
if 'ConnectionError' in tb.etype:
return [Suggestion(title='Network Issue', detail='Check API connectivity.')]Then register it inside RuleEngine.__init__().
{
"failures": [
{
"case": 1,
"etype": "NameError",
"message": "name 'DatFram' is not defined",
"suggestions": [
{
"title": "Add missing import for 'DataFrame'",
"detail": "`DataFrame` exists elsewhere. Consider importing it.",
"fixes": ["from pandas import DataFrame"],
"score": 0.9
}
]
}
]
}- CI/CD pipelines: Automatically parse test failures and upload suggestions to build logs.
- IDE plugins: Hook into linting or test runners to suggest quick-fixes in real time.
- LLM copilots: Feed
--jsonoutput into an LLM to generate automated PR patches.
- Python 3.8+
pytestinstalled on PATH
Pull requests are welcome — feel free to extend the rule set or improve the parsing accuracy.
If you build something cool on top of AutoFix (e.g., a VSCode integration), let’s connect!