any_int = ArgumentFunctionValidator(lambda v: isinstance(v, int), "firstArgument", 0, display='AnyInt()')
any_intArgumentFunctionValidator(argument_name:firstArgument, position=0): AnyInt()
Goal: Evaluate whether a call like f(1,"s") matches any signature-pattern. A signature pattern might be defined like f(1, str). This should match any call that passes the exact value one for the first argument and any object of type str in the second.
We break the task down to validating a single argument. The signature of such an ArgumentValidator should look like :
ArgumentValidator (*args, **kwargs)
Interface for all argument validators.
The most flexibility can be achieved by constructing an ArgumentValidator that evaluates an arbitrary function:
ArgumentFunctionValidator (func:pymoq.core.AnyCallable[bool], name:str, position:int, display:str|None=None)
Validate an argument by evaluating an arbitrary function
This could now be used like:
any_int = ArgumentFunctionValidator(lambda v: isinstance(v, int), "firstArgument", 0, display='AnyInt()')
any_intArgumentFunctionValidator(argument_name:firstArgument, position=0): AnyInt()
In later stages there should be convenience methods around creating such argument validators. E.g. from_type(some_type) for making the above easier.
argument_validator_from_argument (argument:Any, name:str, position:int, verbose:bool=False)
Passing a valid ArgumentValidator simply returns it:
Passing a callable constructs an ArgumentFunctionValidator:
ArgumentFunctionValidator(argument_name:a, position=0): callable()
ArgumentFunctionValidator(argument_name:a, position=0): any_int
Passing a non-callable assumes that the value should be compared against, i.e. it’s a constant:
ArgumentFunctionValidator(argument_name:a, position=0): == 123
AnyInt (name:str, position:int, display:str|None=None)
Special validator that provides methods for integers
AnyInt().greather_than(5)
AnyInt().greather_than_or_equal(5)
AnyInt().less_than(5)