Skip to content

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

Open
@txemi

Description

@txemi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions