Skip to content

alternative repr that does not look like it can be evaluated #41

@wbolster

Description

@wbolster

the repr() generated by attrs looks something like this by default:

MyClass(a=1, b=2)

this is fine in simple cases. however, when using init=False, and implementing my own __init__(), this repr() is misleading since it looks like code that can be evaluated, while actually it is not (and if it is, it's not an intended usage pattern anyway). what about having something like this instead for those cases:

<MyClass a=1 b=2>

...which is still very useful (e.g. for debugging), and it resembles a bit what python produces for classes that do not implement a custom __repr__():

>>> x = object()
>>> x
<object object at 0x7f6cda0c45e0>

obviously, this custom repr() behaviour would require explicit enabling. a flag to attr.s(), e.g. attr.s(use_eval_repr=False) (please come up with a better name), would make sense to me.

what do you think?

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