On Thu, Mar 19, 2020 at 11:38:28PM +0000, Samuel Colvin wrote:

> But it also looks for a "__pretty__" method on objects, and if found uses
> that to display the object.

Are you aware that dunder names are reserved for Python's use?


> The challenge here is that "__pretty__" can't just return a string as that
> leaves all the formatting up to that method, rather than the
> printing/display library. So devtools expects "__pretty__" to yield objects
> in name, value pairs (or just values for list like objects), devtools then
> takes care of recursively displaying the values next to each name.

Perhaps I don't understand the context here, but that doesn't sound like 
a general approach that would work very well. How would you "prettify" a 
scalar object which isn't a sequence and doesn't have name/value pairs?

For that matter, if your library is expecting a stream of either (name, 
value) pairs, or just values, how does it distinguish genuine (name, 
value) pairs from values that look like (name, value) pairs but actually 
represent something else?

I'm just not seeing how a display library can possibly know the right 
way to prettify an arbitrary object if you don't ask the object itself. 
As far as I can tell, pprint itself works because it only knows about a 
handful of special objects, it doesn't try to do anything too special 
with arbitrary objects it knows nothing about.



-- 
Steven
_______________________________________________
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/GMRPSSQW3SXNCP4WU7SYDINL67M2WLQI/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to