Comments (7)
I guess list_of()
, dict_of()
validators may be useful.
from attrs.
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.
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.
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.
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.
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.
@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)
- Define defaults for subclass that uses validator of parent class? HOT 1
- Multiple inheritance produces a TypeError (though dataclasses work fine) HOT 2
- How to derive multiple fields from one complex input dict? HOT 1
- 23.2.0: pytest fails in `tests/test_funcs.py::TestAssoc::test_unknown` unit HOT 1
- make_class(): Populate the __annotations__ dict HOT 3
- License file not included in distribution HOT 1
- Docs should clearly describe `pyright` interaction patterns. HOT 3
- Using `typing.Annotated` HOT 4
- Pyright 1.1.359 broke our CI
- Mypy 1.10 broke our CI
- Error from mypy when using converters in a list HOT 6
- Crash when annotating type with the python syntax (a: T = attrib()) HOT 2
- modulenotfounderror: no module named attrs for version 21.2.0 HOT 1
- `kw_only` with `default` breaks `__attrs_pre_init__` call
- Add "resolve_types" argument to attrs.define() HOT 1
- Typing error when defining an enum of an attrs class
- `__getattr__` in child class gets called when mixed with `cached_property` HOT 7
- Pass kwargs to __attrs_pre_init__() HOT 1
- [Feature Request] Mechanism for adding per-attribute docstrings to __slots__
- `attr.filters.exclude` or `include` not simultaneously usable with `validators.in_` set. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from attrs.