3 ms·
You can use attrs validators for it, though it's not maximally concise. (i.e. you need functions declared, but it's easy to reuse them.) http://www.attrs.org/e
by kemayo 9y ago
You can use attrs validators for it, though it's not maximally concise. (i.e. you need functions declared, but it's easy to reuse them.)
http://www.attrs.org/en/stable/examples.html#validators http://www.attrs.org/en/stable/examples.html#validators
Also, the next attrs release looks like it's getting some support for PEP484 type hinting annotations, but I don't know the details beyond having glanced at some pull requests. So it might get simpler in the future. If so, that'd make it easy to trust the type-validation, and just have the range check as a custom validator.