Thank you for your interest in contributing to python-introspect! This document provides guidelines and instructions for contributing.
-
Fork the repository on GitHub
-
Clone your fork locally:
git clone https://github.com/YOUR_USERNAME/python-introspect.git cd python-introspect -
Add the upstream repository:
git remote add upstream https://github.com/trissim/python-introspect.git
- Python 3.9 or higher
- pip package manager
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install the package in development mode with dev dependencies:
pip install -e ".[dev]"
This will install:
- pytest and pytest-cov for testing
- ruff for linting
- black for code formatting
- mypy for type checking
pytest tests/pytest tests/ --cov=python_introspect --cov-report=term --cov-report=htmlView the HTML coverage report by opening htmlcov/index.html in your browser.
pytest tests/test_signature_analyzer.pypytest tests/test_signature_analyzer.py::TestSignatureAnalyzer::test_analyze_simple_functionpytest tests/ -vWe use automated tools to maintain consistent code style:
# Check for linting issues
ruff check src/ tests/
# Auto-fix issues where possible
ruff check src/ tests/ --fix# Check formatting
black --check src/ tests/
# Auto-format code
black src/ tests/mypy src/python_introspect/# Run all quality checks at once
ruff check src/ tests/ && \
black --check src/ tests/ && \
mypy src/python_introspect/ && \
pytest tests/ -v- Clarity over cleverness - Write code that is easy to understand
- Document your code - Use docstrings for all public APIs
- Test your code - Add tests for new features and bug fixes
- Follow conventions - Match the existing code style
- Keep it simple - Avoid unnecessary complexity
Use Google-style docstrings:
def analyze_function(func: Callable) -> Dict[str, ParameterInfo]:
"""Extract parameter information from a function.
Args:
func: The function to analyze
Returns:
Dictionary mapping parameter names to ParameterInfo objects
Raises:
SignatureAnalysisError: If function signature cannot be analyzed
Examples:
>>> def example(x: int, y: str = "test"):
... pass
>>> params = analyze_function(example)
>>> params["x"].param_type
<class 'int'>
"""
pass- Use type hints for all function parameters and return values
- Use
typingmodule for complex types (List, Dict, Optional, etc.) - Keep type hints accurate and up-to-date
- Test coverage - Aim for high test coverage (>90%)
- Test naming - Use descriptive test names:
test_analyze_function_with_defaults - Test organization - Group related tests in classes
- Test independence - Tests should not depend on each other
- Edge cases - Test edge cases and error conditions
-
Ensure all tests pass:
pytest tests/
-
Ensure code meets style guidelines:
black src/ tests/ ruff check src/ tests/
-
Update documentation if needed
-
Add tests for new features
-
Create a new branch for your changes:
git checkout -b feature/my-new-feature
-
Make your changes and commit them:
git add . git commit -m "Add feature: brief description"
-
Push to your fork:
git push origin feature/my-new-feature
-
Open a Pull Request on GitHub
- Title: Use a clear, descriptive title
- Description: Explain what changes you made and why
- Link issues: Reference any related issues
- Tests: Include tests for new functionality
- Documentation: Update docs if needed
- One feature per PR: Keep PRs focused on a single feature or fix
Use clear, descriptive commit messages:
Add feature: support for parsing NumPy-style docstrings
- Implement NumPy docstring parser
- Add tests for NumPy format
- Update documentation with examples
When reporting bugs, please include:
- Description: Clear description of the bug
- Steps to reproduce: Minimal code to reproduce the issue
- Expected behavior: What you expected to happen
- Actual behavior: What actually happened
- Environment: Python version, OS, package version
- Traceback: Full error traceback if applicable
Example:
## Bug: SignatureAnalyzer fails on dataclasses with factory defaults
### Description
SignatureAnalyzer raises AttributeError when analyzing dataclasses with default_factory.
### Steps to Reproduce
```python
from dataclasses import dataclass, field
from python_introspect import SignatureAnalyzer
@dataclass
class Config:
items: list = field(default_factory=list)
analyzer = SignatureAnalyzer()
analyzer.analyze(Config) # Raises AttributeErrorShould successfully analyze the dataclass and return parameter info.
- Python 3.11
- python-introspect 0.1.0
- Ubuntu 22.04
### Feature Requests
When requesting features, please include:
1. **Use case**: Describe the problem you're trying to solve
2. **Proposed solution**: How you'd like it to work
3. **Alternatives**: Other approaches you've considered
4. **Additional context**: Any other relevant information
## Development Workflow
### Keeping Your Fork Updated
```bash
# Fetch upstream changes
git fetch upstream
# Merge upstream main into your local main
git checkout main
git merge upstream/main
# Push updates to your fork
git push origin main
# Create separate branches for each feature
git checkout -b feature/feature-1
# Work on feature 1...
git checkout main
git checkout -b feature/feature-2
# Work on feature 2...If you have questions about contributing:
- Check existing issues and discussions
- Open a new issue with the "question" label
- Reach out to the maintainers
By contributing to python-introspect, you agree that your contributions will be licensed under the MIT License.
Thank you for contributing to python-introspect! Your efforts help make this project better for everyone.