55from makefun import with_signature
66
77from valid8 .base import Failure , result_is_success , get_callable_names , get_callable_name , _failure_raiser , \
8- WrappingFailure , _none_accepter , _none_rejecter , _LambdaExpression
8+ WrappingFailure , _none_accepter , _none_rejecter , as_function
99
1010try : # python 3.5+
1111 from typing import Callable , Union , List , Tuple
1414 except ImportError :
1515 pass
1616
17- CallableAndFailureTuple = Tuple [Union [Callable , _LambdaExpression ], Union [str , 'Type[Failure]' ]]
17+ try :
18+ from mini_lambda import x
19+ CallableType = Union [Callable , type (x )]
20+ except ImportError :
21+ CallableType = Callable
22+
23+ CallableAndFailureTuple = Tuple [CallableType , Union [str , 'Type[Failure]' ]]
1824 """ Represents the allowed construct to define a failure raiser from a validation function: a tuple """
1925
20- ValidationFunc = Union [Callable , _LambdaExpression , CallableAndFailureTuple ]
26+ ValidationFunc = Union [CallableType , CallableAndFailureTuple ]
2127 """ Represents the 'typing' type for a single validation function """
2228
2329 ValidationFuncs = Union [ValidationFunc , List ['ValidationFuncs' ]] # recursion is used here ('forward reference')
2430 """ Represents the 'typing' type for 'validation_func' arguments in the various methods """
31+
2532except ImportError :
2633 pass
2734
@@ -46,7 +53,7 @@ def _process_validation_function_s(validation_func, # type: ValidationFunc
4653 * List[<ValidationFunc>(s)]. The list must not be empty.
4754
4855 <ValidationFunc> may either be
49- * a callable or a mini-lambda expression (instance of _LambdaExpression - in which case it is automatically
56+ * a callable or a mini-lambda expression (instance of LambdaExpression - in which case it is automatically
5057 'closed').
5158 * a Tuple[callable or mini-lambda expression ; failure_type]. Where failure type should be a subclass of
5259 valid8.Failure. In which case the tuple will be replaced with a _failure_raiser(callable, failure_type)
@@ -79,12 +86,11 @@ def _process_validation_function_s(validation_func, # type: ValidationFunc
7986 # now validation_func is a non-empty list
8087 final_list = []
8188 for v in validation_func :
82- if isinstance (v , _LambdaExpression ):
83- # special case of a _LambdaExpression: automatically convert to a function
84- # note: we have to do it before anything else (such as .index) otherwise we may get failures
85- final_list .append (v .as_function ())
89+ # special case of a LambdaExpression: automatically convert to a function
90+ # note: we have to do it before anything else (such as .index) otherwise we may get failures
91+ v = as_function (v )
8692
87- elif isinstance (v , tuple ):
93+ if isinstance (v , tuple ):
8894 # convert all the tuples to failure raisers
8995 if len (v ) == 2 :
9096 if isinstance (v [1 ], str ):
0 commit comments