Coder Social home page Coder Social logo

Comments (3)

spy16 avatar spy16 commented on June 18, 2024

Any validator is a generic validator (Simple list of string choices is only one of the possibilites here). Following example demonstrates what i mean:

lambdas = validators.Any([lambda x: x > 100, lambda x: x < 0, "hello", {str: int}])

lambdas.validate( <value> )

In above example, the <value> will be validated without error in any of the following case:

  1. If value is an integer greater than 100
  2. If value is an integer less than 0
  3. If value is string "hello"
  4. If value is a dict with string keys and integer values

Printing out "value was not one of " followed by the above list would be cryptic since it would print out lambda functions and dicts in the error message

Simply put, the syntax of Any is Any([validator1, validator2,....]) and is not Any(["str1", "str2",...]).

Also, if the list of validators is very long, error message would end up being long too.

from pyschemes.

crdoconnor avatar crdoconnor commented on June 18, 2024

In which case something like::

Value was not one of "x > 100", "x < 0", "hello", "{str: int}"

Would be clearer.

(code inside lambdas can be extracted using the inspect module.)

Also, if the list of validators is very long, error message would end up being long too.

So truncate?

from pyschemes.

spy16 avatar spy16 commented on June 18, 2024

Yes both are possible and I too believe that the error message for Any validator would be better that way.. I did not get enough time to format it. So it is left as it is. That said, if someone adds this and creates a PR, I would happily merge it.

from pyschemes.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.