Changelog¶
5.1.2 - Bugfix with custom error formatting¶
Fixed issue: custom help messages in ValidationError using several variables were not rendering to string correctly and instead were displaying Error while formatting the help message. Fixes #58
5.1.1 - packaging improvements¶
- packaging improvements: set the "universal wheel" flag to 1, and cleaned up the
setup.py. In particular removed dependency tosixfor setup. Fixes #57
5.1.0 - PEP561 compliance¶
-
Package was made PEP561 compatible. Fixed #55
-
Improved type hints for decorators so that they do not make the decorated item loose its type hints. Fixed #56
-
Removed usage of
@with_signaturein favour of stub file in theentry_points_annotations.py. Fixed #50
5.0.6 - Minor improvements¶
Improved getfullargspec so as to cover more builtins in python 3.
5.0.5 - bugfix - support for numpy True¶
Numpy True can be used (again) as a success condition in validation functions. Fixed #53
5.0.4 - pyproject.toml¶
Added pyproject.toml.
5.0.3 - bug fixes¶
Fixed bug with mini-lambda < 2.2. Fixed #48.
Fixed bug in is_in when the reference object was a non-set container. Fixed #47.
5.0.2 - Bug fix¶
Fixed regression with non-able detection. Fixed #46.
5.0.0 - More betterness!¶
Better syntax for *validation_func:
-
you can provide a
tuple(<callable>, <help_msg>, <failure_type>)to define a single failure raiser (before only(<callable>, <help_msg>)or(<callable>, <failure_type>)were supported). Fixes #33 -
you can provide a
dict-like to define several validation functions, where the key and values can contain<callable>,<help_msg>,<failure_type>. For example{<help_msg>: (<callable>, <failure_type>)}is supported. Fixes #40. -
nested lists are however not supported anymore
-
the
<callable>can now either have signaturef(v),f(*args),f(*args, **ctx)orf(v, **ctx), where**ctxcan be used to receive contextual information. Fixes #39
validation_lib should be imported explicitly
- symbols from
valid8.validation_libare not imported automatically at package root anymore. You need to import them fromvalid8.validation_lib. This speeds up the library's import especially when you do not use the built-in functions. So instead offrom valid8 import is_evenyou should now dofrom valid8.validation_lib import is_even(orfrom valid8 import validation_lib as vlib+vlib.is_even). Fixed #35.
Major exceptions refactoring
-
the main validation function in a
Validatoris now always a failure raiser, even if a single callable was provided. This major design choice made many simplifications possible in particular the string representation of exceptions (below). Fixes #44 -
The string representation of
ValidationErrorandValidationFailurewas greatly improved. In particularValidationErrordoes not display the name and outcome of the validation function anymore (since it is always a failure, see above), andValidationFailurenow has a "compact" string representation option in a newto_str()method, used in composition messages to simplify the result. Composition failures are also represented in a more compact way. -
failure_raisermoved tobasesubmodule with its associated type hintsValidationCallableandValidationCallableOrLambda. It now only accepts a single validation function argument ; this is more intuitive and separates concerns with the other higher-level functions. If you used it with several inputs in the past, you can useand_(...)instead, it will be strictly equivalent to the old behaviour. -
new
@as_failure_raiserdecorator to create a failure raiser by decorating an existing validation function. Fixes #36. -
WrappingFailuredoes not exist anymore, it was merged withFailureclass for architecture simplification. So there are two main exception classes in valid8 now:ValidationErrorandValidationFailure. When the validation callable does not raise an instance ofValidationFailureitself, theInvalidsubclass is used. Fixes #41
Misc
-
assert_subclass_ofnow exposed at root level (for consistency withassert_instance_of, to be used in the context manager entry point) -
Added
__version__attribute to comply with PEP396, following https://smarie.github.io/python-getversion/#package-versioning-best-practices. Fixes #38. -
result_is_successis now inlined and does not use a set expression anymore. Fixed #37 - Improved all examples of
Failurein the validation lib to show how a better practice where thehelp_msgstays at class level but can be overridden failure instance by failure instance. -
Removed
length_betweenopen_left/rightarguments as it does not make sense, to continue fixing #29 -
new subpackage
utilswhere all util submodules now live - New submodule
common_syntaxwhere all the logic to handle the*validation_funcinput syntax resides -
some type hints renamed for clarity:
- before:
ValidationFuncs/ValidationFunc/CallableType/Callable - now:
OneOrSeveralVFDefinitions/ValidationFuncDefinition/ValidationCallableOrLamba/ValidationCallable. ValidationFuncsstill exists as a short alias forOneOrSeveralVFDefinitions.
- before:
-
fixed a few type hints too: tuples with unlimited length were not declared correctly. Now using the ellipsis
Tuple[<type>, ...].
4.2.1 - Minor error message fix¶
Error messages improvements: removed the brackets in Wrong value: [...] for the Failure details. Fixed #32.
4.2.0 - validation lib improvements¶
-
Removed the useless 'strict' length validators: removed
min_len_strictandmax_len_strictinvalidateentry point, and removedstrictargument invalidation_lib'sminlenandmaxlen. Indeed length is an integer by python framework definition, so it is always more compact to do +1 or -1 to the number. Fixes #29. -
New
emptyandnon_emptybuilt-in validators invalidation_lib. Newemptyargument invalidate. Fixes #31.
4.1.2 - Bugfix for python 3.5.2¶
Fixed #30 again, and fixed issue with python 2 appearing with the fix.
4.1.1 - Bugfix for python 3.5.2¶
Fixed #30.
4.1.0 - validate instance/subclass fix¶
assert_instance_ofandassert_subclass_of(used in thevalidateinline entry point) fixed so as to supportEnumtypes. Fixed #28. Important: onlytupleare now supported when several types are provided invalidate'sinstance_ofandsubclass_ofarguments. This is to has a closer behaviour to the python stdlib.
4.0.1 - better mini-lambda compliance¶
- Adapted code to leverage latest
mini_lambda. Fixes #27.
4.0.0 - python 2.7 support + minor improvements¶
-
Python 2.7 is now supported. This fixes #25.
-
Dependencies updated: now
makefunis used instead ofdecoratorto create signature-preserving wrappers.decopatchis also used to create all the decorators consistently. -
assert_instance_ofandassert_subclass_of(used in thevalidateinline entry point) were improved so as to benefit from python 3's capability to compare with several classes, and so that users can provide the reference classes as an iterable rather than a set. Fixes #26. -
More compact tracebacks for
validatemethod: removed exception causes. -
Fixed type inspection for old python 3.5 versions.
3.7.3 - python 3.7 support¶
- Fixed #24
3.7.2 - Bug fix¶
- Fixed #23
3.7.1 - Bug fix¶
- Fixed #22
3.7.0 - Typos detection and np.nan handling¶
3.6.0 - Error messages improvements + create_manually class method in ValidationError¶
- values with string representation larger than 100 characters are not anymore displayed in the error messages by default. Fixes #19
- new class method
ValidationError.create_manuallyto create validation errors manually in some edge cases, without a validator entry point
3.5.5 - Fixed import * issue¶
- Fixes #18
3.5.4 - Improved init¶
- The init file has been improved so as not to export symbols from other packages. Fixes #15
3.5.3 - fixed optionality detection bug¶
- internal custom copy of
typing_inspectmodule was correct for old versions of python but created a bug on new versions of python: optionality detection was not working anymore when usingOptional[]. Fixes #16
3.5.2 - support for older version of typing.py¶
- removed dependency to
typing_inspectmodule so that the module also runs with very old versions of typing.py
3.5.1 - Improved tracebacks¶
- Fixed #14
3.5.0 - improved PEP484-nonable detection¶
- Now relying on typing_inspect to check if an argument is nonable, with support of
TypeVarandUnionincluding nesting.
3.4.0 - new features¶
-
Inline validation:
validatehas a new argumentcustomwhere you can provide a callable method, or a list (same than for the decorators)
-
Examples:
- one page per example - now with a dedicated test in the sources
-
mini-lambda support: now providing an
Instance_ofmini-lambda equivalent ofinstance_of, to raise properTypeError. See example 3 for usage
3.3.0 - new features¶
-
Inline validation:
validatehas several new arguments:subclass_of,contains,subset_of,superset_of,length,equalsvalidatorhas a new argument:subclass_of- New base function
assert_subclass_of instance_ofandsubclass_ofare now dual functions: they can both serve as a function generators or as a simple functions for inline validation for example inside avalidatorcontext manager.
-
Decorators:
- 2 new function generators
has_lengthandcontains
- 2 new function generators
-
Bug fixes:
- Fixed bug #11 where
ValidationErrorcould not be correctly printed in case of a templating issue.
- Fixed bug #11 where
-
New examples in the documentation
3.2.0 - new names and aliases for readability¶
wrap_validcontext manager was renamedvalidationwith aliasvalidator. The deprecated old name remains accepted until next major release 4.x.quick_validfunction was renamedvalidate. The deprecated old name remains accepted until next major release 4.x.@validatedecorator was renamed@validate_io. The old name is now used to denotequick_valid, see above. Itsalidatealias was removed (was it used anyway ?)
3.1.0 - new instanceof parameter¶
quick_valid's parametersallowed_typesandallowed_valueswere renamedinstance_ofandis_inrespectively.instance_ofparameter has been added towrap_validtoo. This solved #10assert_instance_offunction is now available for use withwrap_valid
3.0.1 - fixed bug with wrap_valid when run from a terminal¶
- Fixed #8 (OSError when executing from interpreter terminal)
3.0.0 - new inline validators + dynamic exception typing¶
-
Added two new entry points that should be more useful and usable than
assert_validfor inline validation:quick_validfor limited but simple one-line validation (most common tasks)wrap_validfor more flexible validation (a contextmanager so it takes 2 lines)
-
ValidationErrordoes not inherit fromValueErroranymore. Instead an exception type is dynamically created with the appropriate base class (eitherValueErrororTypeError) when a validation exception is raised. This can be disabled by explicitly inheriting from one or the other in custom exception types. -
improved documentation overall
-
Now compliant with old versions of
typingmodule:typing.Typeis not imported explicitly anymore.
2.1.0 - new annotation @validate_field¶
- @validate_field allows users to validate class fields, whether they are descriptors, properties, or constructor arguments. Check the documentation for details!
2.0.0 - Major improvements and refactoring¶
-
New and improved entry points:
- Function inputs validation:
@validate_argmay be used instead of@validateto add input validation argument by argument instead of all in the same decorator (same functionality, this is just a question of style). A new decorator@validate_outis provided. The manual decoratorvalidate_decoratewas also renameddecorate_with_validationfor clarity - Inline validation: two new functions
assert_validandis_valid, allowing users to perform validation anywhere in their code in defensive programming mode (assert_valid) or case handling mode (is_valid) - Common Validator class: the common logic behind all the above entry points. It offers two methods for defensive programming (
validator.assert_valid) and case handling (validator.is_valid). It may also be used directly by users, to 'pre-compile' validators, so that they are not constructed at every call like when usingassert_validandis_valid. But the difference is probably negligible.
- Function inputs validation:
-
Clearer separation of concepts:
- Entry points (the above) know the full validation context, and raise
ValidationError(or a subclass such asInputValidationErroror your custom subclass) when validation fails. TheValidationErrorobject holds all information available concerning that validation context, and may be used by your application to improve or internationalize error messages. - Base validation functions (your methods or the ones from utility libraries including valid8) may raise subclasses of
FailureorWrappingFailureif they wish to benefit from this helper type as well as ease application-level error handling and internationalization. The helper methodfailure_raiserallows to add such a friendly exception to a method not raising it (such as a lambda).
- Entry points (the above) know the full validation context, and raise
-
Better syntax to define base validation functions in entry points:
- base validation function(s) can be provided as a callable, a tuple(callable, help_msg_str), a tuple(callable, failure_type), or a list of several such elements.
- Nested lists are supported and indicate an implicit
and_(such as the main list). - mini_lambda expressions can be used instead of callables, they will be transformed to functions automatically.
- Tuples indicate an implicit
failure_raiser. Combined with mini_lambda, this is a very powerful way to create validation functions:(Len(s) > 0, 'The value should be an empty string')or(Len(s) > 0, EmptyStringFailure).
-
Minor improvements of the base functions library
- split in independent files
collections,comparables,numbersin avalidation_libsubmodule so as to ease maintenance and possible contributions in the future - added
length_betweenvalidator - added type validation functions
instance_ofandsubclass_of - all functions now raise unique subclasses of
Failure('eat your own dog food') - Most built-in validator generators have their corresponding
__name__now correctly set resulting in more user-friendly error messages
- split in independent files
-
Improvements of the composition operators
and_,or_,xor_now support variable number of arguments (no need to pass a list anymore)not_,and_,or_,xor_now raise consistent exceptions (subclasses ofCompositionFailure), with a user-friendly error message indicating the detailed validation results.
-
A lot of new tests
1.0.0 - First public version¶
- Initial fork from autoclass 1.8.1