Skip to content

Add Bool(strict=False) to to use truthyness of object#272

Open
frmdstryr wants to merge 3 commits into
nucleic:mainfrom
frmdstryr:bool-strict
Open

Add Bool(strict=False) to to use truthyness of object#272
frmdstryr wants to merge 3 commits into
nucleic:mainfrom
frmdstryr:bool-strict

Conversation

@frmdstryr
Copy link
Copy Markdown
Contributor

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.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.53%. Comparing base (2f8fd13) to head (ed6e09d).

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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MatthieuDartiailh
Copy link
Copy Markdown
Member

I am not a fan of adding another coercion like behavior. But I can understand the need. Could you add changelog entry ?

@sccolbert
Copy link
Copy Markdown
Member

sccolbert commented May 29, 2026

Apparently GH is now blocking my email replies, so here I am... :sigh:

Can't you already do this with a Coerced atom? That's why I made that Atom, for the rare case that you need to coerce something to a different type...

Pretty sure Coerced(bool) is all you need for this...

@sccolbert
Copy link
Copy Markdown
Member

sccolbert commented May 29, 2026

If it's a perf issue, I'd need to see some evidence for a real use case where it makes a real difference...

@frmdstryr
Copy link
Copy Markdown
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants