bloomberg / attrs-strict

Provides runtime validation of attributes specified in Python 'attr'-based data classes.
Apache License 2.0
52 stars 19 forks source link

Add support for callables #18

Closed erikseulean closed 4 years ago

erikseulean commented 5 years ago

The current implementation doesn't have support for callables but I think this could be implemented as well. We can use inspect to check the signature of a specific callable and validate the arguments and return type based on the attribute declaration in the attrs dataclass

Describe the solution you'd like

@attrs
class SomeClass:
    factorial = attr.ib(
         type=Callable[[List[int]] , List[int]],
         validator=type_validator
    ) 
erikseulean commented 4 years ago

Done!