Metadata-Version: 2.1
Name: guardtypes
Version: 1.0.2
Summary: Enforces type annotations at runtime
Author: Brandon Volesky
Project-URL: Repository, https://github.com/bvolesky/guardtypes
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: dev
Requires-Dist: black==24.4.2; extra == "dev"
Requires-Dist: ruff==0.4.8; extra == "dev"
Requires-Dist: isort==5.13.2; extra == "dev"
Requires-Dist: pytest==8.2.2; extra == "dev"
Requires-Dist: mypy==1.10.0; extra == "dev"
Requires-Dist: twine==5.1.0; extra == "dev"

# guardtypes

`guardtypes` is a Python library that enforces type annotations at runtime. It provides a decorator, `enforce`, that checks the types of function arguments and return values against their type hints, raising a `TypeError` if a mismatch is found.

## Installation

To install `guardtypes`, use pip:

```sh
pip install guardtypes
```

## Usage

### Basic Example

The `enforce` decorator can be used to enforce type annotations on function arguments and return values.

```python
from guardtypes import enforce


@enforce
def add(a: int, b: int) -> int:
    return a + b


# This will raise a TypeError because 'b' is not an int
add(1, '2')
```

### Handling Local Context

The `guardtypes` decorator also handles local context, allowing you to use class types within the same function.

```python
from guardtypes import enforce


class Cat:
    def __init__(self, name: str):
        self.name = name

    @staticmethod
    @enforce
    def create(name: str) -> 'Cat':
        return Cat(name)


# This will create an instance of Cat
cat = Cat.create("Whiskers")

# This will raise a TypeError because 'name' should be a str
cat = Cat.create(123)
```

## License

This project is licensed under the MIT License.
