[Python-ideas] decorator vs. 'with' analogy [was: Syntax for loop invariants]

2020-03-19 Thread Stephen J. Turnbull
Andrew Barnert via Python-ideas writes: > [A] context manager seems perfect. It allows you to hint any > statement, including a loop statement, by adding whatever code you > want that gets run before and after the statement. I wonder: The analogy "decorator : function :: with : suite" seems us

[Python-ideas] Re: decorator vs. 'with' analogy [was: Syntax for loop invariants]

2020-03-19 Thread Alex Hall
Yes https://docs.python.org/3/library/contextlib.html#contextlib.ContextDecorator On Thu, Mar 19, 2020 at 3:26 PM Stephen J. Turnbull < [email protected]> wrote: > Andrew Barnert via Python-ideas writes: > > > [A] context manager seems perfect. It allows you to hint any > > st

[Python-ideas] Re: decorator vs. 'with' analogy [was: Syntax for loop invariants]

2020-03-19 Thread Andrew Barnert via Python-ideas
On Mar 19, 2020, at 06:23, Stephen J. Turnbull wrote: > > Andrew Barnert via Python-ideas writes: > >> [A] context manager seems perfect. It allows you to hint any >> statement, including a loop statement, by adding whatever code you >> want that gets run before and after the statement. > > I

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

2020-03-19 Thread Marco Sulla
On Mon, 16 Mar 2020 at 22:22, Andrew Barnert via Python-ideas wrote: > I think the best solution is to just not have a SortedList. C++, Java, etc. > don’t provide anything like that Guava has TreeMultiset: https://guava.dev/releases/snapshot/api/docs/com/google/common/collect/TreeMultiset.html

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

2020-03-19 Thread Andrew Barnert via Python-ideas
On Mar 19, 2020, at 11:29, Marco Sulla wrote: > > On Mon, 16 Mar 2020 at 22:22, Andrew Barnert via Python-ideas > wrote: >> I think the best solution is to just not have a SortedList. C++, Java, etc. >> don’t provide anything like that > > Guava has TreeMultiset: > https://guava.dev/releases/

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

[Python-ideas] Re: Syntax for loop invariants

2020-03-19 Thread Steven D'Aprano
On Wed, Mar 18, 2020 at 09:26:52PM -0700, Andrew Barnert via Python-ideas wrote: > > On Mar 18, 2020, at 04:22, haael wrote: > > > > What is bugging me is the assymetry: there is a nice way to hint functions, > > but there is none to hint loops. > > Then Steve’s suggestion of a context manager

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

2020-03-19 Thread Steven D'Aprano
On Thu, Mar 19, 2020 at 07:28:56PM +0100, Marco Sulla wrote: > On Mon, 16 Mar 2020 at 22:22, Andrew Barnert via Python-ideas > wrote: > > I think the best solution is to just not have a SortedList. C++, Java, etc. > > don’t provide anything like that > > Guava has TreeMultiset: > https://guava.d

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

[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 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: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 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 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 wi