Skip to content

engmaryamameen/pytype

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

PyType - Advanced Python Static Type Checker

Python License Tests Coverage PyPI

A clean, modular, and extensible Python static type checker designed for modern Python development.

πŸš€ Features

  • 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

πŸ“¦ Installation

From Source

git clone https://github.com/engmaryamameen/pytype.git
cd pytype
pip install -e .

Development Installation

pip install -e ".[dev]"

πŸ› οΈ Usage

Basic Usage

# 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

Configuration File

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"]

πŸ—οΈ Architecture

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

Core Components

  • cli.py: Command-line interface and argument parsing
  • checker.py: Handles type checking logic and validation
  • infer.py: Performs type inference on unannotated code
  • analyzer.py: AST parsing and semantic analysis
  • reporter.py: Formats and outputs errors and warnings
  • config.py: Manages configuration loading and validation

πŸ§ͺ Testing

Run the test suite:

# Run all tests
pytest

# Run with coverage
pytest --cov=pytype

# Run specific test file
pytest tests/test_checker.py

πŸ”§ Development

Code Quality

This project uses several tools to maintain code quality:

  • Black: Code formatting
  • Ruff: Linting and import sorting
  • Pytest: Testing framework
  • Coverage: Test coverage reporting

Pre-commit Setup

# Install pre-commit hooks
pre-commit install

# Run all hooks
pre-commit run --all-files

πŸ“ Example Output

Text Format

[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'

JSON Format

{"file": "myfile.py", "line": 12, "message": "Expected int, got str in function 'add'", "type": "type_mismatch", "severity": "error"}

🀝 Contributing

We welcome contributions! Here's how you can help:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Setup

# 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 .

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ’– Support This Project

If you find PyType helpful and would like to support its development, consider:

β˜• Buy Me a Coffee

Buy Me a Coffee

⭐ Star the Repository

If you can't contribute financially, starring this repository helps a lot!

GitHub stars

πŸ› Report Issues

Found a bug? Have a feature request? Open an issue!

πŸ“ Improve Documentation

Help improve the documentation or add examples!

πŸ‘₯ Contributors

Thanks goes to these wonderful people:


engmaryamameen

πŸš€ Project Creator & Maintainer

This project follows the all-contributors specification. Contributions of any kind welcome!

πŸ™ Acknowledgments

  • 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! πŸš€

About

A lightweight Python static type checking and inference tool.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published

Languages