Ticket #8934 (assigned)
Inconsistent usage of IntArrayBoundedValidator in Python
Reported by: | Martyn Gigg | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | Backlog |
Component: | Python | Keywords: | |
Cc: | Blocked By: | ||
Blocking: | Tester: |
Description
Dear Mantid team, I just stumbled accross some inconvenience as I wanted to declare an array property where the individual values are supposed to have a minimum, but not a maximum value.
For single numbers it is very convenient:
self.declareProperty('SingleNonNegativeInt', 0,
direction = Direction.Input, doc = "a non-negative integer", validator=IntBoundedValidator(lower=0.))
But for an array it does not work like this:
theProp = IntArrayProperty(name='PositiveNumbers',
validator = IntArrayBoundedValidator(lowerBound=1), direction = Direction.Input)
self.declareProperty(theProp, doc = "Positive integers")
# (Nasty anyway that here it is 'lowerBound' # whereas for non-arrays it is 'lower'...)
This is because 'IntArrayBoundedValidator' does not have default arguments nor understands 'None'. This is the workaround:
onlyLowerBound = IntArrayBoundedValidator(lowerBound=1, upperBound=1) onlyLowerBound.clearUpper() theProp = IntArrayProperty(name='PositiveNumbers',
validator = onlyLowerBound, direction = Direction.Input)
self.declareProperty(theProp, doc = "Positive integers")
Would be nice if setting bounds on single values or arrays would behave similarly (and in an easy way)...
bulk move to assigned at the into of the triage step