Comments (5)
Oh, and if one wants an attrib to be required, that has to be implemented with a validator?
from attrs.
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 and
ing and or
ing 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.
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.
@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.
…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)
- Validation happens only after the creation of all fields, which can be too late HOT 2
- Private field is not understood by VScode. HOT 4
- `AttributeError` when accessing an attribute with a default value set in a child class HOT 4
- Way to specify KW_ONLY location in the constructor like in dataclass.KW_ONLY
- complain on mutable default HOT 1
- Collections of inner validators for `deep_iterable`/`deep_mapping`
- Typing problem for validator collections
- Wrong error message for inner validators
- Optional inner validators for `deep_mapping`
- Add support for marking classes `typing.final` HOT 3
- Is it possible to validate all attribute types by default?
- Convenience decorators for promoting functions to attrs-compatible validators HOT 4
- 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 1
- License file not included in distribution HOT 1
- Docs should clearly describe `pyright` interaction patterns. HOT 2
- Using `typing.Annotated` 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.