Skip to content

Commit f534d0e

Browse files
author
Sylvain MARIE
committed
Fixed import error
1 parent f21224a commit f534d0e

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

valid8/composition.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from makefun import with_signature
66

77
from 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

1010
try: # python 3.5+
1111
from typing import Callable, Union, List, Tuple
@@ -14,14 +14,21 @@
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+
2532
except 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

Comments
 (0)