Add Bool(strict=False) to to use truthyness of object#272
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #272 +/- ##
=======================================
Coverage 97.52% 97.53%
=======================================
Files 24 24
Lines 1093 1095 +2
Branches 167 168 +1
=======================================
+ Hits 1066 1068 +2
Misses 13 13
Partials 14 14 🚀 New features to boost your workflow:
|
|
I am not a fan of adding another coercion like behavior. But I can understand the need. Could you add changelog entry ? |
|
Apparently GH is now blocking my email replies, so here I am... :sigh:
|
|
If it's a perf issue, I'd need to see some evidence for a real use case where it makes a real difference... |
|
Yes Coerced(bool) can be used instead, but there's already strict arguments for the Int, Float, Str, and Bytes members so this is mainly for consistency. If it's unwanted then this can be closed, it's not a big deal. |
This adds a new bool_promote validation mode that uses the value's truthyness to determine the saved value.
Since this pushes the number of validators over 32 the enum needs another bit. To avoid adding extra padding (and make room for any potential future validators), the index was moved into the packed struct and changed to uint16_t (since catom only supports u16 anyways).
Using a negative index is now an error. This is potentially breaking but I think also a user error so that's ok in my opinion.