A clean, modular, and extensible Python static type checker designed for modern Python development.
- Static Type Checking: Parse and analyze
.py
files for type annotations - Type Inference: Infer variable and return types using AST analysis
- CLI Tool: Easy-to-use command-line interface with rich options
- Modular Architecture: Clean separation of concerns with extensible design
- Rich Error Reporting: Colored CLI output and JSON export for CI/CD
- Configuration Support: TOML-based configuration files
git clone https://github.com/engmaryamameen/pytype.git
cd pytype
pip install -e .
pip install -e ".[dev]"
# Check a single file
pytype myfile.py
# Check a directory
pytype myproject/
# Show inferred types
pytype --infer myfile.py
# Auto-fix with inferred types
pytype --fix myfile.py
# Strict mode (treat missing types as errors)
pytype --strict myfile.py
# JSON output for CI/CD
pytype --format=json myfile.py
# Use custom config
pytype --config=pytype.toml myfile.py
Create a pytype.toml
file in your project root:
[tool.pytype]
strict = false
infer = true
fix = false
format = "text"
exclude = ["tests/", "migrations/"]
ignore_errors = ["E501", "F401"]
PyType follows a layered, modular architecture:
pytype/
βββ __init__.py # Package initialization and exports
βββ cli.py # Command-line interface and argument parsing
βββ checker.py # Core type checking logic
βββ infer.py # Type inference engine
βββ analyzer.py # AST parsing and analysis
βββ config.py # Configuration management
βββ reporter.py # Error reporting and output formatting
cli.py
: Command-line interface and argument parsingchecker.py
: Handles type checking logic and validationinfer.py
: Performs type inference on unannotated codeanalyzer.py
: AST parsing and semantic analysisreporter.py
: Formats and outputs errors and warningsconfig.py
: Manages configuration loading and validation
Run the test suite:
# Run all tests
pytest
# Run with coverage
pytest --cov=pytype
# Run specific test file
pytest tests/test_checker.py
This project uses several tools to maintain code quality:
- Black: Code formatting
- Ruff: Linting and import sorting
- Pytest: Testing framework
- Coverage: Test coverage reporting
# Install pre-commit hooks
pre-commit install
# Run all hooks
pre-commit run --all-files
[ERROR] myfile.py:12: Expected int, got str in function 'add'
[WARNING] myfile.py:25: Missing return type annotation for function 'process_data'
[INFO] myfile.py:30: Inferred type: List[str] for variable 'items'
{"file": "myfile.py", "line": 12, "message": "Expected int, got str in function 'add'", "type": "type_mismatch", "severity": "error"}
We welcome contributions! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
# Clone and install in development mode
git clone https://github.com/engmaryamameen/pytype.git
cd pytype
pip install -e ".[dev]"
# Run tests
pytest
# Run linting
ruff check .
# Format code
black .
This project is licensed under the MIT License - see the LICENSE file for details.
If you find PyType helpful and would like to support its development, consider:
If you can't contribute financially, starring this repository helps a lot!
Found a bug? Have a feature request? Open an issue!
Help improve the documentation or add examples!
Thanks goes to these wonderful people:
engmaryamameen π Project Creator & Maintainer |
This project follows the all-contributors specification. Contributions of any kind welcome!
- Inspired by tools like
mypy
,pyright
, and Google's pytype - Built with modern Python best practices
- Designed for extensibility and maintainability
Thank you for your support! π