Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no validating collection attributes #39

Closed
RonnyPfannschmidt opened this issue Apr 18, 2016 · 7 comments
Closed

no validating collection attributes #39

RonnyPfannschmidt opened this issue Apr 18, 2016 · 7 comments
Labels

Comments

@RonnyPfannschmidt
Copy link

currently its not possible to declare an attribute that's something like a list of Elements or a mapping of string to integer

@hynek hynek changed the title no validating collection attriubtes no validating collection attributes Apr 18, 2016
@hynek
Copy link
Member

hynek commented Apr 18, 2016

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

@ghost
Copy link

ghost commented Sep 10, 2016

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.

@exarkun
Copy link

exarkun commented Jan 11, 2017

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.

@erikseulean
Copy link

erikseulean commented Dec 14, 2018

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 ?

@hynek
Copy link
Member

hynek commented Dec 15, 2018

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?

@erikseulean
Copy link

@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

@hynek
Copy link
Member

hynek commented Aug 15, 2019

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. 🙈

@hynek hynek closed this as completed Aug 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants