Giter VIP home page Giter VIP logo

Comments (7)

hynek avatar hynek commented on June 29, 2024 1

I guess list_of(), dict_of() validators may be useful.

from attrs.

hynek avatar hynek commented on June 29, 2024 1

The overall problem is that while those validators look useful, in practice you usually need more sophisticated validation and end up using a true validation framework anyway (that can be used from within attrs just fine).

So I'm not sure this is really worth adding and whether we should get on the slippery slope of growing an inadequate validation framework that will just lead to people asking for more features and yet us never reach the power of something like voluptuous?

from attrs.

hynek avatar hynek commented on June 29, 2024 1

I'm fine with adding anything that's useful to the wiki! So far I had no reason to remove anything.


That said, I believe this ticket has been already fixed in #425! Yeah, I can be inconsistent too. 🙈

from attrs.

 avatar commented on June 29, 2024

This is fairly easy to do if you just write your own validator. There will almost always be a need to do that for when you want to validate not just an object's type, but that it falls in a certain range, e.g. non-negative integer.

from attrs.

exarkun avatar exarkun commented on June 29, 2024

A testtools_matches along with the various matchers at http://testtools.readthedocs.io/en/latest/for-test-authors.html#combining-matchers would also address this.

from attrs.

erikseulean avatar erikseulean commented on June 29, 2024

Is this still something that's worth adding ? I was thinking of something like:

If a more generic option is recommended, like container_of with some helpers (as mentioned in the other closed PR) I'd be willing to implement this as long as we define the scope of it and the requirements.
If I gathered all the data from the other PR, would be nice to have something like:

container_of(container_type, validators, empty_ok=True, none_ok=True)
On top of this there could be some helpers as list_of set_of etc.

@hynek could you please comment on this ?

from attrs.

erikseulean avatar erikseulean commented on June 29, 2024

@hynek is this something that's worth having as a separate library, eventually added here https://github.com/python-attrs/attrs/wiki/Extensions-to-attrs that would provide validators to containers ? We have a version currently that allows you to create validators for containers (list_of, set_of, dict_of) plus a generic function that allows you to implement your own container validators at my workplace and I'm willing to open source it, if you consider it could bring some potential value.

Does it makes sense to have this alongside the typing capabilities specified here ?
http://www.attrs.org/en/stable/types.html

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.