python-attrs / python-attrs/attrs
Mockup of quick expression validator syntax
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.8k
- Forks
- 480
- Avg merge
- 2h 15m
- Merged PRs (30d)
- 2
Description
Here's a quick mockup of the idea.
The idea is to provide a special token VAL that constructs validators using magic methods so you can write:
@attr.s
class Test:
positive = attr.ib(validator=[VAL.isa(int, float), VAL > 0.0])
nonempty = attr.ib(validator=[VAL.len() >= 1])
And, of course, it can report the expression in the exception it raises.
Things to support in a real version:
__getitem__to check keys__getattr__to allow property and method checks- the other operators, especially
inand such __call__validates in the mockup, butattr.ibshould tell the object to convert itself to a validator
I'd like to see what the community thinks before putting together a proper PR.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the linked mockup and the existing attr.ib validator behavior. No implementation files or tests are named, and the requested scope includes multiple magic methods, operators, and conversion behavior. Done would require community agreement on the syntax and a properly scoped implementation with tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- developer-experience
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100