Implement Predicate decorator#146
Conversation
|
Thank you for your contribution! Hmm, this looks useful, but I don't know if the verbose way is currently so big a pain to justify including this predicate in the library. On the other hand, it can't hurt, but it does make the library a bit more complicated. You're literally replacing this: some_condition = Schema(some_condition, error="Error message")with this: @Predicate(error="Error message")correct? The latter is more readable, true, but I'm not sure that's not enough justification to include this. Does anyone else want to chime in? |
a559457 to
730d978
Compare
Codecov Report
@@ Coverage Diff @@
## master #146 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 1 1
Lines 208 212 +4
=====================================
+ Hits 208 212 +4
Continue to review full report at Codecov.
|
gst
left a comment
There was a problem hiding this comment.
the fact is that there are 2 different things, the schema (or condition validator) and the function condition itself.. one might reuse the condition in other places and thus the decorator is ineffective given the behavior is changed ; the resulting schema can't be called as if it was the condition..
but the idea is still interesting I think.
| @Predicate("ERROR2", ignore_extra_keys=True) | ||
| def p2(x): | ||
| return x == 2 | ||
| assert p2._error is "ERROR2" and p2._ignore_extra_keys |
Hello. I added
Predicatedecorator.Currently, To define a functional schema, We have to write a
defstatement and an assignment statement.Predicatemake it possible to define a functional schema as onedefstatement.I feel later style is more readable (in the same reason of
@getterdefining properties).