https://github.com/wazedkhan/enforcer
A lightweight Python decorator to enforce type hints at runtime
https://github.com/wazedkhan/enforcer
decorator python runtime-type-checking type-hints
Last synced: about 1 month ago
JSON representation
A lightweight Python decorator to enforce type hints at runtime
- Host: GitHub
- URL: https://github.com/wazedkhan/enforcer
- Owner: WazedKhan
- License: mit
- Created: 2024-11-20T01:30:47.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-11-20T19:02:18.000Z (over 1 year ago)
- Last Synced: 2025-11-28T00:24:45.412Z (3 months ago)
- Topics: decorator, python, runtime-type-checking, type-hints
- Language: Python
- Homepage: https://pypi.org/project/static-type-enforcer/0.1.0/
- Size: 22.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Roadmap: ROADMAP.md
Awesome Lists containing this project
README
# Enforcer
**Enforcer** is a lightweight Python decorator for enforcing type hints at runtime. It ensures that function arguments match their specified types, providing a simple and intuitive solution for runtime type validation.
## Features
- Enforce type hints at runtime for functions.
- Lightweight and dependency-free.
- Compatible with Python 3.7 and later.
## Installation
You can install Enforcer via pip : `pip install static-type-enforcer==0.1.0`
```python
from enforcer import enforce_types
@enforce_types
def greet(name: str, age: int):
print(f"{name} is {age} years old!")
# Valid call
greet("Alice", 25)
# Invalid call
greet("Alice", "twenty-five") # Raises TypeError
```
## Contributing
Contributions are welcome! Please check the [issues](https://github.com/WazedKhan/enforcer/issues) for tasks that need help.