python-attrs / python-attrs/attrs

Support for a validator argument to enable runtime validation

Open
#739 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Feature
Dominant language
Python
Stars
5.8k
Forks
480
Avg merge
2h 15m
Merged PRs (30d)
2

Description

A while ago I created https://github.com/bloomberg/attrs-strict a library to help with runtime validation of attrs classes.

The way it currently works is you need to "enable" it per attribute in the following manner:
attr.ib(validator=type_validator(), type=List[Tuple[str, str]])

But if you have multiple fields, and you want to apply the validation on all of them, it becomes repetitive. Additionally, you might miss adding it for some attributes.

Would you consider an argument that could enable it for all the existing attributes in an attrs class ?
Something along the lines:

attr.s(validate_with=type_validator())
class Something:
   ...

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the attr.s and attr.ib APIs and the linked attrs-strict library to understand the proposed validator flow. Done means a class-level option can apply the requested validator to all existing attributes without repeating validator= on each field, with the behavior agreed and verified in the project’s 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
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.