Skip to content

Add positional-only parameters #641

@Dr-ZeeD

Description

@Dr-ZeeD

With PEP 570, positional-only parameters were introduced.
Similarly to keyword-only parameters, I would like to see these as an option for attrs.
One thing that makes them "special" is that the __repr__ method would behave differently for positional-only parameters than it would for regular positional parameters.

An example I would use in my libraries:

from attr import attrib, attrs


@attrs(auto_attribs=True)
class Point:
    """A three-dimensional point."""
    _data: Tuple[float, float, float] = attrib(positional_only=True)


print(Point((0, 1, 2)))

The output would then be

Point((0, 1, 2))

instead of

Point(_data=(0, 1, 2))

If this were a desirable feature, would this be a good "first pull request" I could follow up on?

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