The desire for this came up for me in relation to a set of dataclasses used to 
define a tree structure where each item has a reference to its parent. 
Including the complete expansion of the parent (with its children and its 
parent with its children, etc.) is WAY too much information, but at the same 
time, I do want to at least identify the parent. Currently, the only way to get 
what I'm looking for is to write a custom `__repr__` from scratch.

It would be great if there was at least 1 way to take advantage of the 
automatic repr and still customize its handling for specific fields.

The first thing I thought of in that regard for my example was to add a 
`parent_name` property using `@property` and specify `repr=False` for `parent. 
The auto-generated repr is not aware of properties defined that way though. 
Maybe that could be solved by adding an argument named something like 
`descriptor=<True|False>` to `field()` where a `True` value means that getting 
and setting happens through a separately defined descriptor (e.g. 
via`@property`) and should not be implemented automatically, even though it 
should be otherwise treated as a dataclass property.

The second thought I had is to be able to customize `repr` for any field. One 
way to do that might be to allow `field()`'s `repr` argument to accept a method 
name string and/or a callable that accepts an instance of the class in addition 
to accepting `True` or `False`.

I actually like the idea of having both of those capabilities.

Opinions?
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/BE5I4MXLPBW3RUKSV5M35CEJRJHISKNW/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to