GithubHelp home page GithubHelp logo

Multiple validators? about attrs HOT 5 CLOSED

python-attrs avatar python-attrs commented on May 6, 2024
Multiple validators?

from attrs.

Comments (5)

mjmare avatar mjmare commented on May 6, 2024

Oh, and if one wants an attrib to be required, that has to be implemented with a validator?

from attrs.

hynek avatar hynek commented on May 6, 2024

attrs comes with two validators: https://attrs.readthedocs.org/en/stable/api.html#validators . Calling them a “bunch” may be a bit of a stretch but I didn’t want to reword once they grow. :)

I had some code in place for anding and oring validators but it felt a bit academic so I took it out for now again until I come up with a compelling use case.

Attributes are always required unless you supply a default value.

from attrs.

mjmare avatar mjmare commented on May 6, 2024

and/or validators seem pretty useful to me in order to make validators more granular. But other validator will likely be needed more, like ranges, or select from list or...

from attrs.

econchick avatar econchick commented on May 6, 2024

@mjmare (not a maintainer, just an avid user of attrs) - you can write & supply your own validators and not rely on @hynek to write more default ones.

For instance, I've written a lot of validators for ramlfications - an example: the version of the RootNode validates with this function.

Not sure if that helps at all 😄 but attrs' validation is definitely one of the main reasons I chose this library when writing my library.

from attrs.

hynek avatar hynek commented on May 6, 2024

…and you can totally put them on PyPI either if you think they’re generally useful. :) I’m trying to learn from the mistakes I did with characteristic and keep the scope small on purpose while giving users ways to extend attrs to their liking.

from attrs.

Related Issues (20)

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.