[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-31 Thread Wes Turner
Bump to CC Re: "[Python-ideas] pretty-printing in the terminal" On Sun, Mar 22, 2020, 8:53 PM Kyle Stanley wrote: > I ended up opening an issue for it at https://bugs.python.org/issue40045. > > > On Sun, Mar 22, 2020 at 8:33 PM Kyle Stanley wrote: > >> Chistopher

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-22 Thread Kyle Stanley
I ended up opening an issue for it at https://bugs.python.org/issue40045. On Sun, Mar 22, 2020 at 8:33 PM Kyle Stanley wrote: > Chistopher Barker wrote: > > I'd suggest you make a PR on the docs. > > Yeah I was planning on either doing that, or opening it as a "newcomer

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-22 Thread Kyle Stanley
Chistopher Barker wrote: > I'd suggest you make a PR on the docs. Yeah I was planning on either doing that, or opening it as a "newcomer friendly"/"easy" issue on bugs.python.org. IMO, it could make for a decent first PR. On Sun, Mar 22, 2020 at 1:28 PM Christopher Barker wrote: > On Fri, Mar

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-22 Thread Christopher Barker
On Fri, Mar 20, 2020 at 8:24 PM Stephen J. Turnbull < turnbull.stephen...@u.tsukuba.ac.jp> wrote: > Single leading underscore is reserved for class-private use, so you > could more safely use "sunders" (_pretty_) or "splunders" (_pretty__). > Though this use case really isn't "class-private" --

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-22 Thread Christopher Barker
On Fri, Mar 20, 2020 at 8:52 PM Kyle Stanley wrote: > > > https://docs.python.org/3/reference/lexical_analysis.html#reserved-classes-of-identifiers > > I remembered the existence of this rule and tried to locate it recently > (prior to this discussion), but was unable to because it doesn't

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-21 Thread Andrew Barnert via Python-ideas
On Mar 20, 2020, at 19:32, Christopher Barker wrote: > > It’s a bit ironic: if you have a nifty idea for Python, you are often told to > try it out on your own. And if you expect it to maybe make its way into > Python, you’d want to use a dunder... > > But then, dunders are reserved for the

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-21 Thread Stephen J. Turnbull
Samuel Colvin writes: > > I'd be interested to see the "display utility" point of view expanded. > > For me there are two use cases: These both seem to be what I would consider "debugging" use cases, ie, displaying whole objects to users who have some understanding of the internals. My

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-21 Thread Samuel Colvin
> I'd be interested to see the "display utility" point of view expanded. For me there are two use cases: I use devtool's debug() command instead of print() ALL THE TIME when debugging, so does the rest of my office and others who I've demonstrated its merits to. I use this sitecustomize trick

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-21 Thread Stephen J. Turnbull
Steven D'Aprano writes: > Oh, that's interesting. I mostly think of pretty-printing as a display > utility aimed at end users. Well, I'm mostly the only end-user of my code, so there's definitely a bias here. I'd be interested to see the "display utility" point of view expanded. Steve

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-21 Thread Paul Moore
On Sat, 21 Mar 2020 at 06:42, Steven D'Aprano wrote: > > On Sat, Mar 21, 2020 at 12:16:29PM +0900, Stephen J. Turnbull wrote: > > > The way I think of pprint (FWIW, YMMV) is as a debug utility. > > Oh, that's interesting. I mostly think of pretty-printing as a display > utility aimed at end

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-21 Thread Steven D'Aprano
On Sat, Mar 21, 2020 at 12:16:29PM +0900, Stephen J. Turnbull wrote: > The way I think of pprint (FWIW, YMMV) is as a debug utility. Oh, that's interesting. I mostly think of pretty-printing as a display utility aimed at end users. -- Steven ___

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-20 Thread Kyle Stanley
Steven D'Aprano wrote: > Yes, really. > > https://docs.python.org/3/reference/lexical_analysis.html#reserved-classes-of-identifiers I remembered the existence of this rule and tried to locate it recently (prior to this discussion), but was unable to because it doesn't explicitly mention "dunder".

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-20 Thread Stephen J. Turnbull
Samuel Colvin writes: > Hi Steven, > > > Are you aware that dunder names are reserved for Python's use? > > I wasn't aware it was explicitly discouraged, thanks for the link. > > It seems to me that "__pretty__" (however it's implemented) seems a very > sensible name for a method used

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-20 Thread Christopher Barker
It’s a bit ironic: if you have a nifty idea for Python, you are often told to try it out on your own. And if you expect it to maybe make its way into Python, you’d want to use a dunder... But then, dunders are reserved for the standard library. It’s a pickle. And it’s not like there’s no

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-20 Thread Samuel Colvin
Hi Steven, > Are you aware that dunder names are reserved for Python's use? I wasn't aware it was explicitly discouraged, thanks for the link. It seems to me that "__pretty__" (however it's implemented) seems a very sensible name for a method used when pretty printing objects. If it's one day

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-20 Thread Angus Hollands
------ > From: Chris Angelico > To: "Steven D'Aprano" > Cc: python-ideas > Bcc: > Date: Fri, 20 Mar 2020 15:37:08 +1100 > Subject: [Python-ideas] Re: dunder methods for encoding & prettiness aware > formal & informal representations > On Fri, Mar 20, 20

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-20 Thread Steven D'Aprano
On Fri, Mar 20, 2020 at 06:30:24PM +1300, Greg Ewing wrote: > On 20/03/20 4:55 pm, Steven D'Aprano wrote: > > >Are you aware that dunder names are reserved for Python's use? > > Nobody is going to put you in jail if you use an unofficial dunder > name. You just run the risk that your use of it

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-19 Thread Greg Ewing
On 20/03/20 4:55 pm, Steven D'Aprano wrote: Are you aware that dunder names are reserved for Python's use? Nobody is going to put you in jail if you use an unofficial dunder name. You just run the risk that your use of it will conflict with some official use in the future. -- Greg

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-19 Thread Steven D'Aprano
On Fri, Mar 20, 2020 at 03:37:08PM +1100, Chris Angelico wrote: > "Subject to breakage without warning" technically applies to a *lot* > of things that aren't guaranteed. Yes? > Using __pretty__ as a protocol is no different from any of those. If we should choose to use a `__pretty__` dunder,

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-19 Thread Chris Angelico
On Fri, Mar 20, 2020 at 3:28 PM Steven D'Aprano wrote: > > On Fri, Mar 20, 2020 at 03:01:16PM +1100, Chris Angelico wrote: > > On Fri, Mar 20, 2020 at 2:59 PM Steven D'Aprano wrote: > > > > > > On Thu, Mar 19, 2020 at 11:38:28PM +, Samuel Colvin wrote: > > > > > > > But it also looks for a

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-19 Thread Steven D'Aprano
On Fri, Mar 20, 2020 at 03:01:16PM +1100, Chris Angelico wrote: > On Fri, Mar 20, 2020 at 2:59 PM Steven D'Aprano wrote: > > > > On Thu, Mar 19, 2020 at 11:38:28PM +, Samuel Colvin wrote: > > > > > But it also looks for a "__pretty__" method on objects, and if found uses > > > that to display

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-19 Thread Chris Angelico
On Fri, Mar 20, 2020 at 2:59 PM Steven D'Aprano wrote: > > On Thu, Mar 19, 2020 at 11:38:28PM +, 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

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-19 Thread Steven D'Aprano
On Thu, Mar 19, 2020 at 11:38:28PM +, 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

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-16 Thread C. Titus Brown
(no reason to moderate a topic that wanders off what you think is the linear path, Rob… no one is violating CoC and that’s mostly what I care about) > On Mar 16, 2020, at 6:11 PM, Rob Cliffe via Python-ideas > wrote: > > This makes on my count 6 messages on arcane mathematical topics that

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-16 Thread Rob Cliffe via Python-ideas
This makes on my count 6 messages on arcane mathematical topics that have nothing to do with the original proposition, which was to do with prettyprinting. Don't get me wrong - I enjoy such discussions as much as anyone, considering myself a mathematician of sorts.  But it must be frustrating

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-16 Thread David Mertz
On Mon, Mar 16, 2020, 5:57 AM Stephen J. Turnbull < turnbull.stephen...@u.tsukuba.ac.jp> wrote: > s/people/mathematicians/ and I'd agree with you. But I did write "people". > Are mathematicians not people? :-) If they are, them "some mathematicians" implies "some people."

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-16 Thread Barry Scott
> On 16 Mar 2020, at 20:59, James Edwards wrote: > > I would love a formalized, for example, __pretty__ hook. Many of our classes > have __pretty__ and __json__ "custom" dunders defined and our PrettyPrinters > / JSONEncoders have checks for them (though the __pretty__ API has proven >

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-16 Thread James Edwards
I would love a formalized, for example, __pretty__ hook. Many of our classes have __pretty__ and __json__ "custom" dunders defined and our PrettyPrinters / JSONEncoders have checks for them (though the __pretty__ API has proven difficult to stabilize). w/r/t to repurposing __str__, I

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-16 Thread Andrew Barnert via Python-ideas
On Mar 16, 2020, at 02:54, Stephen J. Turnbull wrote: > > Andrew Barnert writes: > >> Well, there are an infinite number of ever larger infinite >> ordinals, ω or ω_0 being the first one, and likewise an infinite >> number of infinite cardinal, aleph_0 being the first one, and >> people

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-16 Thread Christopher Barker
> > On Mon, Mar 16, 2020, 1:04 AM Greg Ewing > wrote: > >> >> Also, strs and reprs of arbitrary objects often end up in places >> such as log files which aren't equipped to handle unicode or other >> fancy things. So keeping them as basic as possible is a good idea. >> > > Is this why __unicode__

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-16 Thread Wes Turner
On Mon, Mar 16, 2020, 3:41 AM Andrew Barnert via Python-ideas < python-ideas@python.org> wrote: > On Mar 15, 2020, at 22:37, Stephen J. Turnbull < > turnbull.stephen...@u.tsukuba.ac.jp> wrote: > > > > > > Because they're not always available, even in 2020. Also, ∞ is > > ambiguous; it's used for

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-16 Thread Steven D'Aprano
On Mon, Mar 16, 2020 at 01:25:13AM -0400, Wes Turner wrote: [Greg] > > Also, strs and reprs of arbitrary objects often end up in places > > such as log files which aren't equipped to handle unicode or other > > fancy things. So keeping them as basic as possible is a good idea. > > > > Is this

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-16 Thread Steven D'Aprano
On Sun, Mar 15, 2020 at 11:37:53PM -0400, Wes Turner wrote: > Monkeypatching the __str__ or __repr__ of a builtin is generally > undesirable because that's global and not thread safe. Monkeypatching the __str__ or __repr__ of a builtin is generally impossible. py> int.__repr__ = lambda self:

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-16 Thread Stephen J. Turnbull
Andrew Barnert writes: > Well, there are an infinite number of ever larger infinite > ordinals, ω or ω_0 being the first one, and likewise an infinite > number of infinite cardinal, aleph_0 being the first one, and > people rarely use the ∞ symbol for any of them. s/people/mathematicians/

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-16 Thread Andrew Barnert via Python-ideas
On Mar 15, 2020, at 22:37, Stephen J. Turnbull wrote: > > > Because they're not always available, even in 2020. Also, ∞ is > ambiguous; it's used for the ordinal number infinity (IIRC, more > precisely denoted ω), the cardinal number infinity, the positive limit > of the real line, the

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Stephen J. Turnbull
Christopher Barker writes: > So [inf and -inf] are not "readable input, part of Python syntax", > but they are part of the float API. Thank you for the correction. Aside: help(float) doesn't mention these aspects of the API. I guess that since 1.0 / 0.0 doesn't return float("inf") and 0.0 /

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Wes Turner
On Mon, Mar 16, 2020, 1:04 AM Greg Ewing wrote: > On 16/03/20 2:27 pm, Christopher Barker wrote: > > I imagine a LOT of code out there (doctests, who know > > what else) does in fact expect the str() of builtins not to change -- so > > this is probably dead in the water. > > Also, strs and reprs

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Greg Ewing
On 16/03/20 2:27 pm, Christopher Barker wrote: I imagine a LOT of code out there (doctests, who know what else) does in fact expect the str() of builtins not to change -- so this is probably dead in the water. Also, strs and reprs of arbitrary objects often end up in places such as log files

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Wes Turner
- CPython has __str__ and __repr__, IPython has obj._repr_fmt_(), MarkupSafe has obj.__html__(), https://github.com/tommikaikkonen/prettyprinter has @register_pretty Neither __str__ nor __repr__ have any round-trip guarantee/expectation (they're not suitable for serialization/deserialization //

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Steven D'Aprano
On Sun, Mar 15, 2020 at 06:27:43PM -0700, Christopher Barker wrote: > Anyway, Python now has two different ways to "turn this into a string":, > __str__ and __repr__. I think the OP is suggesting a third, for "pretty > version". But then maybe folks would want a fourth or fifth, or . > >

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Kyle Stanley
Christopher Barker wrote: > Is there any guarantee (or even string expectation) that the __str__ for an object won't change? > [snip] > *reality check*: I imagine a LOT of code out there (doctests, who know what else) does in fact expect the str() of builtins not to change -- so this is probably

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Christopher Barker
On Sun, Mar 15, 2020 at 6:12 PM Stephen J. Turnbull < turnbull.stephen...@u.tsukuba.ac.jp> wrote: > Also, I'd like to note that "inf" and "-inf" (and "nan" for that > matter) are not "informal". They are readable input, part of Python > syntax: > > % python3.8 > Python 3.8.2 (default, Feb 27

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Stephen J. Turnbull
Jonathan Fine writes: > However, you wrote "decide implicitly". Perhaps I'm missing something in > the "implicitly". That's shorthand for the long form I used later: "depending on variable environment state" (such as encodings, user id, or sunspot activity). Should have done it in the

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Eric V. Smith
On 3/15/2020 12:50 PM, Steve Jorgensen wrote: Guido van Rossum wrote: I think the idea you're looking for is an alternative for the pprint module that allows classes to have formatting hooks that get passed in some additional information (or perhaps a PrettyPrinter object) that can affect the

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Steve Jorgensen
Alex Hall wrote: > Might be helpful to look at https://github.com/tommikaikkonen/prettyprinter > and https://github.com/wolever/pprintpp Right! Thx. :) ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Steve Jorgensen
Jonathan Fine wrote: > Hi Steve (for clarity Jorgensen) > Thank you for your good idea, and your enthusiasm. And I thank Guido, for > suggesting a good contribution this list can make. > Here's some comments on the state of the art. In addition to > https://docs.python.org/3/library/pprint.html >

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Alex Hall
Might be helpful to look at https://github.com/tommikaikkonen/prettyprinter and https://github.com/wolever/pprintpp ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Jonathan Fine
Hi Steve (for clarity Jorgensen) Thank you for your good idea, and your enthusiasm. And I thank Guido, for suggesting a good contribution this list can make. Here's some comments on the state of the art. In addition to https://docs.python.org/3/library/pprint.html there's also

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Jonathan Fine
Hi Steve (for clarity Turnbull) You wrote: Allowing objects to decide implicitly how to represent themselves is usually a bad idea, and we shouldn't encourage it. I'm puzzled. I thought that when I define a class X, I'm generally encouraged to define a __repr__ method, that is used to decide how

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Steve Jorgensen
Guido van Rossum wrote: > I think the idea you're looking for is an alternative for the pprint module > that allows classes to have formatting hooks that get passed in some > additional information (or perhaps a PrettyPrinter object) that can affect > the formatting. > This would seem to be an

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Guido van Rossum
I think the idea you're looking for is an alternative for the pprint module that allows classes to have formatting hooks that get passed in some additional information (or perhaps a PrettyPrinter object) that can affect the formatting. This would seem to be an ideal thing to try to design and put