A Python library for detecting logical and syntactical errors in Python code
Project description
PyBugHunt
Advanced Python Code Error Detection and Analysis
PyBugHunt is a sophisticated Python library designed to detect, analyze, and suggest fixes for both syntactical and logical errors in Python code. Leveraging a combination of static code analysis techniques and advanced transformer-based machine learning models, PyBugHunt offers developers a powerful tool to improve code quality and reduce debugging time.
Table of Contents
- Features
- Technology Stack
- Project Structure
- Installation
- Usage
- Error Detection Capabilities
- Machine Learning Approach
- Development
- License
- Contributing
Features
PyBugHunt offers comprehensive error detection capabilities:
- Robust Syntax Error Detection and Analysis
- Intelligent Logical Error Detection using both static analysis and machine learning.
- Transformer-Based Models:
- CodeBERT: For classifying code as correct or containing a logical error.
- T5 (Text-to-Text Transfer Transformer): For generating natural language descriptions of the detected errors.
- Fix Suggestion System
- Flexible Integration Options (CLI and Python API)
- Customization and Training of models.
Technology Stack
PyBugHunt utilizes a wide range of technologies and libraries:
Core Technologies
- Python 3.8+
- Abstract Syntax Tree (AST)
- Python Standard Library
Machine Learning
- PyTorch
- Hugging Face Transformers (for CodeBERT and T5)
- scikit-learn
- NumPy
Static Analysis
- Astroid
- PyLint
Project Structure
pybughunt/
├── src/
│ └── pybughunt/
│ ├── __init__.py
│ ├── cli.py
│ ├── detector.py
│ ├── logic_analyzer.py
│ ├── syntax_analyzer.py
│ └── models/
│ ├── __init__.py
│ ├── model_loader.py
│ ├── model_trainer.py
│ └── models.py # New file for transformer model definitions
├── tests/
├── .gitignore
├── README.md
├── pyproject.toml
└── setup.py
Installation
From Source
# Clone the repository
git clone https://github.com/Preksha-7/pybughunt.git
cd pybughunt
# Install in development mode
pip install -e .
Dependencies
All dependencies will be automatically installed. The main dependencies are listed in pyproject.toml and setup.py.
Usage
Command Line Interface
Analyze a file with the default static analysis:
python -m pybughunt.cli analyze src/pybughunt/sample_buggy.py --model_type static
Analyze a file using a specific machine learning model:
python -m pybughunt.cli analyze src/pybughunt/sample_buggy.py --model_type codebert --model_path path/to/saved_codebert_model
Train a new model:
python -m pybughunt.cli train --dataset /path/to/python/files --output my_model --model_type codebert
Python API
from pybughunt import CodeErrorDetector
# Initialize the detector with a specific model
detector = CodeErrorDetector(model_type='codebert', model_path='path/to/saved_codebert_model')
code = '''
def incorrect_factorial(n):
if n == 0:
return 1
else:
return incorrect_factorial(n-1) # Missing multiplication with n
'''
results = detector.analyze(code)
print(results)
Error Detection Capabilities
Syntax Errors: Missing delimiters, indentation issues, invalid syntax, etc.
Logical Errors:
- Static Analysis: Infinite loops, unused variables, off-by-one errors, division by zero, unreachable code.
- Machine Learning: More subtle logical errors detected by the trained transformer models.
Machine Learning Approach
PyBugHunt now includes transformer-based models for more advanced logical error detection:
CodeBERT (microsoft/codebert-base): A model pre-trained on a large corpus of code, used for classifying code snippets as either correct or containing a logical error.
T5 (t5-small): A sequence-to-sequence model that can be trained to generate a natural language description of the error in a piece of code.
These models can be trained on your own dataset using the train command in the CLI.
Development
The project is structured to be modular and extensible. You can add new error detection patterns to the logic_analyzer.py or experiment with different models in the models/ directory.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a pull request.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pybughunt-0.2.0.tar.gz.
File metadata
- Download URL: pybughunt-0.2.0.tar.gz
- Upload date:
- Size: 18.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
849b9e2987ef615f079d07b3dc099330c1f8fcd9ad4f18423c6738eb6b2ea64b
|
|
| MD5 |
628904603dc8dca7ebb3538de45cb0a6
|
|
| BLAKE2b-256 |
0f3b2dc4356e4f415e2c6d48bc70a33abc7880cdbde36da55d650f3ae7313386
|
File details
Details for the file pybughunt-0.2.0-py3-none-any.whl.
File metadata
- Download URL: pybughunt-0.2.0-py3-none-any.whl
- Upload date:
- Size: 17.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fae32ce71876929160d46f96eb9884db25fe0dc794d4e52cc775f52197f49f57
|
|
| MD5 |
30d5c7f8126dab9caf94bf69ba12c350
|
|
| BLAKE2b-256 |
5bf188c4176175b578d4f15a66b5de471be08b8dd1126ddea24e6ec6b6015e87
|