python-attrs / python-attrs/attrs

wishlist: attrs.validators.instance_of parse nested types (lists and maps) not needing verbose deep_iterable, deep_map and optional

Open
#1,235 0 comments 0 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

I wish I could write:

validator=attrs.validators.instance_of(typing.Optional[list[int]])

instead of:

validator=attrs.validators.instance_of(
        attrs.validators.optional(attrs.validators.deep_iterable(int)))

It is easier to read and there is not need to use another differente way to express a type, just the standard python way.

Besides it is an step nearer to autodetect type from standard declaration and no need to tell it again in attr deffinition:

@attrs.define
class Myclass:
    _myattr: typing.Optional[list[int]] = attrs.field()

Thanks

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 attrs.validators.instance_of and the existing optional, deep_iterable, and deep_map validators to define how nested typing.Optional, list, and map annotations should be interpreted. Add coverage for the shown Optional[list[int]] form and confirm validation behavior for valid and invalid values.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.