Patterns
Last updated
Last updated
Some parameter types allow us to specify patterns which will be matched against their specified values. Only values which match the pattern are valid and a ValueError
error will be raised for invalid specifications.
The most prominent example is using the String
parameter:
But also the parameter types Bool, Integer, Number,
support patterns. You can access the default pattern of a parameter type via Number.pattern
.
Parameters also support illegal patterns, i.e. patterns that must not be matched, and you can also add your own. They can be accessed via Parameter.illegal_patterns
for example. Up to now each parameter instance of a specific type shares all illegal patterns with all other instances. For example the Integer
type has an illegal pattern that forbids using in in order to prevent ambiguities. If you want to extend a specific instance only with its own illegal patterns you need to copy them over manually:
We can also disable pattern matching for parameters by setting Integer(pattern=False)
.