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

2020-03-20 Thread Angus Hollands
Has anyone mentioned the IPython pretty printer yet? I'm late to the conversation unfortunately, so apologies if someone else already raised it. https://ipython.readthedocs.io/en/stable/api/generated/IPython.lib.pretty.html#IPython.lib.pretty.pretty On Fri, 20 Mar 2020 at 16:02, wrote: > Send Py

[Python-ideas] Re: Formalized pretty & encoding-aware object representation (was dunder methods for...)

2020-03-20 Thread Steve Jorgensen
Steve Jorgensen wrote: > Based on the conversations stemming from my previous post, it is clear that > the topic > was too implementation-specific. It is not clear whether dunder methods are > an appropriate > component of the solution (they might or might not be). > Also, it presumably makes sen

[Python-ideas] Re: Formalized pretty & encoding-aware object representation (was dunder methods for...)

2020-03-20 Thread Eric V. Smith
On 3/16/2020 1:15 PM, Steve Jorgensen wrote: Steve Jorgensen wrote: Based on the conversations stemming from my previous post, it is clear that the topic was too implementation-specific. It is not clear whether dunder methods are an appropriate component of the solution (they might or might no

[Python-ideas] Support max heaps in heapq module

2020-03-20 Thread Abhai Kollara
Hi, I understand that the default implementation of heapq.heapify is to create a min-heap. The logic for max-heapify has already been implemented inside _heapify_max and along with that for corresponding push and pop operations. But they are not exposed to the user and hence not mentioned in any

[Python-ideas] Re: Support max heaps in heapq module

2020-03-20 Thread Joao S. O. Bueno
It is easy to have a wrapper class around the heapq functions so that you can use an arbitrary comparison on the heap. I have an answer with such an snippet, that got some activity today - maybe exactly due to your questioning: https://stackoverflow.com/questions/8875706/heapq-with-custom-compare

[Python-ideas] Re: Adding a built-in data structure with binary search tree semantics

2020-03-20 Thread Marco Sulla
On Fri, 20 Mar 2020 at 05:06, Steven D'Aprano wrote: > On Thu, Mar 19, 2020 at 07:28:56PM +0100, Marco Sulla wrote: > > The problem is: is there a use case? I mean, how much time you need to > > sort a list, add an element and re-sort it? > Depends on whether you are adding and re-sorting *one* el

[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 im

[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 preceden

[Python-ideas] Re: Syntax for loop invariants

2020-03-20 Thread Stephen J. Turnbull
Steven D'Aprano writes: > Wasn't me, it was the other Stephen who spells his name with a "ph" > :-) Guilty as charged, on both counts. > So each loop will need its own context manager, meaning its own > class. The *actual* invariant will be buried far away, in a CM > class, rather than righ

[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 wh

[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 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 ___ Py