Runtime typechecker for dataclass
APACHE-2.0 License
$ pip install dataclass_utils
check_type
functionCheck dataclass type recursively
from dataclass_utils import check_type
import dataclasses
from typing import List
@dataclasses.dataclass
class Foo:
a: int
b: List[List[int]]
import pytest
check_type(Foo(1, [[1])) # OK
with pytest.raises(TypeError):
check_type(Foo(1, [[2, "foo"]])) # NG
See examples directory for more examples.
check_type
can be applied for nested dataclasses, nested containersmake publish
to test and publish