$ pip install dataclass_utils
Check 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.
- Recursively check type for each field in dataclass
check_typecan be applied for nested dataclasses, nested containers
- No dependencies
make publishto test and publish