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)
- 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
- Suggestion: Consider changing the order for variable initialization in `__init__` 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.