Skip to content

Validators need to return bool #349

Closed

Description

@jpoikela

Hi!
I like your library!

I tried to take a short-cut in my state machine, validator returned a list (empty list would mean False) and the error message was not related to the actual problem.

I wonder if it would make sense to emphasize (in example, maybe) that validators need to return bool value.
Or make it checked somehow? if a guard gets something else than a bool, it would log a warning?
Or then, it's also possible to coerce to bool... not sure which is best here.

Activity

  1. fgmacedo commented on Feb 22, 2023

    @fgmacedo
    Owner

    Hi @jpoikela , how are you? Thanks, glad you liked it!

    There's a mismatch here, Validators are expected to raise exceptions:

    Are like Guards, but instead of evaluating to boolean, they are expected to raise an exception to stop the flow.

    If you meant Guards, then you're correct as at 1.0.3 they only work with bool returns, and not with falsy or truthy values like evaluating an empty list as a false value. However, this is already implemented and will be released in the 2.0 version.

    #342: Guards now supports the evaluation of truthy** and falsy values.

    I planned to release 2.0 after #329, but I may consider releasing it before as I'm still trying to work on it.

  2. fgmacedo commented on Feb 22, 2023

    @fgmacedo
    Owner

    Closing as fixed in #342. Feel free to reopen if something else is missing.

  3. jpoikela commented on Feb 24, 2023

    @jpoikela
    Author

    ah, sorry. I was using wrong words and had not read carefully enough, it reads there clearly.
    and truthy values already on your list, cool!
    thanks!

  4. fgmacedo commented on Mar 6, 2023

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions