1- # Authors: Sylvain Marie <[email protected] > 1+ # Authors: Sylvain MARIE <[email protected] > 2+ # + All contributors to <https://github.com/smarie/python-pyfields>
23#
3- # Copyright (c) Schneider Electric Industries, 2019. All right reserved.
4+ # License: 3-clause BSD, <https://github.com/smarie/python-pyfields/blob/master/LICENSE>
45import sys
56from collections import OrderedDict
67
2930 ValidationFunc = Union [Callable [[Any ], Any ],
3031 Callable [[Any , Any ], Any ],
3132 Callable [[Any , Any , Any ], Any ]]
32- """A validation function is a callable with signature (val), (obj, val) or (obj, field, val), returning `True`
33+ """A validation function is a callable with signature (val), (obj, val) or (obj, field, val), returning `True`
3334 or `None` in case of success"""
3435
3536 try :
5556 Iterable [ValidatorDef ],
5657 Mapping [VFDefinitionElement , Union [VFDefinitionElement ,
5758 Tuple [VFDefinitionElement , ...]]]]
58- """Several validators can be provided as a singleton, iterable, or dict-like. In that case the value can be a
59- single variable or a tuple, and it will be combined with the key to form the validator. So you can use any of
59+ """Several validators can be provided as a singleton, iterable, or dict-like. In that case the value can be a
60+ single variable or a tuple, and it will be combined with the key to form the validator. So you can use any of
6061 the elements defining a validators as the key."""
6162
6263 # shortcut name used everywhere. Less explicit
@@ -171,7 +172,7 @@ def make_validator_callable(validation_callable, # type: ValidationFunc
171172 raise ValueError (
172173 "validation function should accept 1, 2, or 3 arguments at least. `f(val)`, `f(obj, val)` or "
173174 "`f(obj, field, val)`" )
174- elif nb_args == 1 or (nb_args == 0 and nbvarargs >= 1 ): # varargs default to one argument (compliance with old mini lambda)
175+ elif nb_args == 1 or (nb_args == 0 and nbvarargs >= 1 ): # varargs default to one argument (compliance with old mini lambda) # noqa
175176 # `f(val)`
176177 def new_validation_callable (val , ** ctx ):
177178 return validation_callable (val )
@@ -337,7 +338,7 @@ def __init__(self, convert_fun, name=None, accepts_fun=None):
337338 ConverterFunc = Union [Callable [[Any ], Any ],
338339 Callable [[Any , Any ], Any ],
339340 Callable [[Any , Any , Any ], Any ]]
340- """A converter function is a callable with signature (val), (obj, val) or (obj, field, val), returning the
341+ """A converter function is a callable with signature (val), (obj, val) or (obj, field, val), returning the
341342 converted value in case of success"""
342343
343344 try :
@@ -364,15 +365,16 @@ def __init__(self, convert_fun, name=None, accepts_fun=None):
364365 Converters = OneOrSeveralConverterDefinitions
365366
366367
367- def make_3params_callable (f , # Union[ValidationFunc, ConverterFunc]
368+ def make_3params_callable (f , # type: Union[ValidationFunc, ConverterFunc]
368369 is_mini_lambda = False # type: bool
369370 ):
370371 # type: (...) -> Callable[[Any, 'Field', Any], Any]
371372 """
372373 Transforms the provided validation or conversion callable into a callable with 3 arguments (obj, field, val).
373374
374375 :param f:
375- :param is_mini_lambda: a boolean indicating if the function comes from a mini lambda. In which case we know the signature has one param only (x)
376+ :param is_mini_lambda: a boolean indicating if the function comes from a mini lambda. In which case we know the
377+ signature has one param only (x)
376378 :return:
377379 """
378380 # support several cases for the function signature
@@ -600,7 +602,7 @@ def __str__(self):
600602 % (self .value_to_convert , err_dct_to_str (self .err_dct ))
601603
602604
603- def err_dct_to_str (err_dct # Dict[Converter, str]
605+ def err_dct_to_str (err_dct # type: Dict[Converter, str]
604606 ):
605607 # type: (...) -> str
606608 msg = ""
@@ -617,7 +619,7 @@ class DetailedConversionResults(object):
617619 __slots__ = 'value_to_convert' , 'field' , 'obj' , 'err_dct' , 'winning_converter' , 'converted_value'
618620
619621 def __init__ (self , value_to_convert , field , obj , err_dct , winning_converter , converted_value ):
620- self .value_to_convert = value_to_convert
622+ self .value_to_convert = value_to_convert
621623 self .field = field
622624 self .obj = obj
623625 self .err_dct = err_dct
0 commit comments