0.10.0 - 2020/01/07
is_decimal
was added which validates if an object is an instance ofdecimal.Decimal
.is_number
was modified to also consider instances ofdecimal.Decimal
as numbers.
0.9.0 - 2020/01/07
Explanation
objects now have a new attributesdata
which holds the data that was used to generate the explanation. Foris_transformed
and any of it's subclasses this will contain the transformed data. For classes likeis_dict_where
where other predicates are ran on parts of it's data it will replace these parts with the data on the explanation of that result.Explanation
objects now have a new methodby_path
that yields tuples of(path, subexplanation)
.Explanation
objects now have a more human readable result when you callrepr
.- Added
is_blank
andis_not_blank
wherevalue
is consideredblank
if and only ifnot value
holds. - Added
is_pre
for adding preconditions to predicates. - Using
is_if
withelse_valid=False
is now deprecated, in this case you should be usingis_pre
instead. - Changed
if_match
so that it now always usessearch
instead ofmatch
orfullmatch
based on thefull
parameter to find the match. Behaviour of match and fullmatch can still be achieved by using the^
and$
characters in your pattern. - Added the
match_as_data
option tois_match
which when set toTrue
will replace the explanation objectsdata
attribute with the match object. - Added the
is_decodable_json_where
predicate which is a combination ofis_decodable_where
andis_json_where
since these two are often used together. - Changed
is_with
so that if a non callable value is provided as a transform function it will be changed into a function that always returns this value. - Added
is_with_context
which is similar tois_with
but operators on the current context instead of the data. - Changed
Wrapper.wrap
to return whatever it wrapped. - Added
is_if.cases
andis_when.cases
as a shorthand for creating long if ... elif ... elif ... else structures without having to nest. - Added
default_context
toutils
to easily specify default values for the predicate context. - Fixed
utils.Wrapper
incorrectly calling the wrapped predicate so that prerequisites were ignored.
0.8.0 - 2019/04/10
- Refactored automatic predicate conversion to convert
dict
,tuple
, andlist
instances tois_dict_where
,is_tuple_where
, andis_list_where
respectively. For normal data this should be functionally equivalent but now you can nest other predicates inside this data. - Moved
to_pred
fromis_eq
to it's own module. - Simplify
assert_valid
into just an assertion function instead of a function generator.
0.7.1 - 2018/07/03
- Refactored
is_json_where
, andis_json
. - Added
is_bytes
,is_decodable_where
, andis_decodable
.
0.7.0 - 2018/03/01
- Made assertions generated by
assert_valid
accept context arguments. These will then be forwarded to the underlying predicate. Theassert_valid
class itself also accepts a context argument in it's constructor that serves as a base context for the generated assertion. - Simplified
is_tranformed
andis_json_where
a bit. This change is backwards incompatible. - Simplified
utils.Wrapper
to only wrap predicates. This way predicate testing using isinstance works for wrapper predicates as well.
0.6.0 - 2018/01/17
Wrapper
class has been updated, it now doesn't just wrap function calls but also underlying attributes of the wrapped object. You now change what is wrapped by callingWrapper.wrap(obj)
instead ofWrapper.func = obj
.- The dict predicates (
is_dict_where
,is_superdict_where
,is_subdict_where
) saw a small overhaul in how their explanation objects work. Instead of just giving an explanation that the keys are incorrect with details about which keys are extra and which are missing the explanation now gives explanation objects that statenot_allowed
ormissing
for these keys while also evaluating the keys that were present and could be evaluated. is_iterable_where
and it's subclasses (is_tuple_of
,is_list_of
) saw a small overhaul in how their explanation objects work. Instead of just giving an explanation that the length is incorrect the explanation now gives explanation objects that stateoverflow
ormissing
for when data is too long or too short for the incorrect indexes while also evaluating the elements that were present and could be evaluated.- Transform methods were added to
is_cond
, withtrans_cond
andtrans_pred
you can alter the data before it gets entered into the conds or preds respectively. By default they just do nothing with the data. is_with
was added. Here you specify a dict of keys mapping to functions and a predicate that then stores the output of that function when the data gets entered for that key. Then in the following predicate you can useGet
-objects to reference to that specific key. See the tests for a good example.is_byte
was added which checks for an int in range 0 to 255.
0.5.1 - 2018/01/12
- Fix bug where
is_dict_of
didn't check if the value was a dict beforehand but only if it was iterable, thus leading to an exception being thrown when a value was evaluated that was iterable but not a dict.
0.5.0 - 2018/01/12
- Introduction of this changelog.
is_dict_where
now also accepts two dicts as arguments to indicate required and optional keys respectively.- The
dict
method onExplanation
objects now has an extra keyword argumentinclude_details=True
to specify if you want it to put the details in the dict. Also if the details are some kind of structure made up out of dicts, lists and tuples it now traverses these structures to also convert allExplanation
objects within them to dicts. (Small breaking change) Wrapper
utility class introduced, this just wraps a function that you can change at any moment by setting thefunc
-attribute. Useful for when you want some kind of recursion in your predicate structure.- Predicate classes
is_optional
andis_nullable
were added, given a predicate they become a predicate that holds when either the given predicate holds or the value isNone
. There are two versions becauseis_optional
andis_nullable
useis_none
andis_null
under the hood respectively. is_cond
now wraps its conds and preds withis_eq
when they are not callable. Consistency :)- Almost complete rewrite without breaking any compatibility making all
predicates be instances of a subclass of
is_valid.base.Predicate
instead of loose functions. This allows for some neat small things:- You can now use
~pred
instead ofis_not(pred)
, alsois_not(is_not(pred))
just gives backpred
now. - You can now use
pred1 | pred2
instead ofis_any(pred1, pred2)
, alsois_any(pred1, is_any(pred2, pred3))
does the same asis_any(pred1, pred2, pred3)
now. - You can now use
pred1 & pred2
instead ofis_all(pred1, pred2)
, alsois_all(pred1, is_all(pred2, pred3))
does the same asis_all(pred1, pred2, pred3)
now. - You can now use
pred.explain(value)
instead ofpred(value, explain=True)
.
- You can now use
0.4.0 - 2017/11/26
- Latest version before introduction of this changelog.