Skip to content

Set default repr=False in @attr.s(), but have individual attrs overwrite #7

@econchick

Description

@econchick

Current behavior:

In [8]: @attr.s(repr=False)
   ...: class Foo(object):
   ...:     x = attr.ib()
   ...:     y = attr.ib(repr=True)
   ...:

In [9]: f = Foo(x="foo", y="bar")

In [10]: f
Out[10]: <__main__.Foo at 0x10a139c50>

Desired behavior:

In [8]: @attr.s(repr=False)
   ...: class Foo(object):
   ...:     x = attr.ib()
   ...:     y = attr.ib(repr=True)
   ...:

In [9]: f = Foo(x="foo", y="bar")

In [10]: f
Out[10]: Foo(y="bar")

Especially useful when you have many attr.ibs but only want one in to actually be in the repr.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions