Annotate min / max values for int / float parameters
For the automatic generation of a Galaxy tool wrapper, it would be beneficial if min/max values would be annotated or parseable.
Maybe it's possible to specify this in a parseable format in the docstring, e.g. min: VAL
.
Maybe type annotation could be done along the following lines (via chatgpt, i.e. not tested)
class ConstrainedInt:
def __init__(self, minimum: int = None, maximum: int = None):
self.minimum = minimum
self.maximum = maximum
def __call__(self, value: int) -> int:
if self.minimum is not None and value < self.minimum:
raise ValueError(f"Value must be greater than or equal to {self.minimum}")
if self.maximum is not None and value > self.maximum:
raise ValueError(f"Value must be less than or equal to {self.maximum}")
return value
def some_function(value: ConstrainedInt(minimum=0, maximum=10)) -> int:
return value
result = some_function(5) # No error, within the specified range
result = some_function(15) # Raises ValueError: Value must be less than or
Not sure if NewType
might be an option.