python-attrs / python-attrs/attrs
alternative repr that does not look like it can be evaluated
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.8k
- Forks
- 480
- Avg merge
- 2h 15m
- Merged PRs (30d)
- 2
Description
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with attr.s and the generated repr() behavior for classes using init=False and a custom init. Review the comment discussion for the intended opt-in naming and output format. Done means the API and representation behavior are agreed and covered for both existing and alternative representations.
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