Skip to content

albr21/py-typify

Repository files navigation

py-typify

A Python module for runtime type checking based on type annotations.

Usage

from typify import Typed, TypedMeta
from dataclasses import dataclass

# Example of using Typed to create a class with type-checked attributes

@dataclass
class MyClass(Typed):
    x: int
    y: str

obj = MyClass(x=10, y="hello")  # This will work
obj = MyClass(x="not an int", y="hello")  # This will raise a TypeError


# Example of using TypedMeta to create a class with type-checked attributes

class MyMetaClass(metaclass=TypedMeta):
    def method_1(self, a: int) -> str:
        return "Hello"

MetaObj = MyMetaClass()
MetaObj.method_1(10)  # This will work
MetaObj.method_1("not an int")  # This will raise a TypeError

Contributing

Check out the CONTRIBUTING file for guidelines on how to contribute to this project.

License

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

About

A Python module enforcing runtimed type checking based on type annotations

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Contributors

Languages