More spec examples
Here’s another example of use:
from dulcinea.spec import any, sequence, require, match
L = [1,2,3,4]
test_is = any(str, sequence(int))
require(L, test_is)
# used like an assert, returns None
match('some string', test_is)
# returns True
require(1234, test_is)
# raises TypeError: iteration over non-sequence
require([1,2,3,'4'], test_is)
# raises
# TypeError:
# Expected: any(str, sequence(int, anything))
# Got: [1, 2, 3, '4']
Read the dulcinea.spec code for more insight – its just over 500 lines and the core is very straightforward