Re: [Python-ideas] As-do statements/anonymous blocks in python

2018-07-26 Thread Steven D'Aprano
I *think* you are trying to find a syntax for "code blocks" like Ruby has, but I'm not sure. Your examples are a little confusing to me (possibly because you have at least three separate suggestions here, "as" blocks, a mysterious "do" keyword I don't understand, and partial application using %

Re: [Python-ideas] Change repr of collections.OrderedDict to be more dict-like

2018-07-26 Thread Robert Vanden Eynde
Thanks for your response, I want to print/repr an OrderedDict() without relying on the fact that "dict are ordered" ie. I want a solution < python 3.7. Currently, if I do repr( OrderedDict([(1,2),(3,4)]) ), I get the string "OrderedDict([(1,2),(3,4)])", I'd like a function that would return the s

Re: [Python-ideas] Change repr of collections.OrderedDict to be more dict-like

2018-07-26 Thread Steven D'Aprano
On Fri, Jul 27, 2018 at 05:30:35AM +, Robert Vanden Eynde wrote: > Currently, what's the best way to implement a function > f(OrderedDict([(1,2),(3,4)])) == '{1: 2, 3: 4}', works for all > possible types, and also availaible for pprint with nice indent? I don't understand the question, and

Re: [Python-ideas] Change repr of collections.OrderedDict to be more dict-like

2018-07-26 Thread Robert Vanden Eynde
Currently, what's the best way to implement a function f(OrderedDict([(1,2),(3,4)])) == '{1: 2, 3: 4}', works for all possible types, and also availaible for pprint with nice indent? If I could set a parameter in ipython or python repl that would print that, that would already be very useful. L

Re: [Python-ideas] Change repr of collections.OrderedDict to be more dict-like

2018-07-26 Thread Steven D'Aprano
On Thu, Jul 26, 2018 at 06:50:20PM -0400, David Mertz wrote: > I often use doctests to verify APIs and behaviors when I update code. I > know I'm in a minority and most developers slightly disparage doctests. I don't know why you think that "most developers" disparage doctests. Perhaps they're th

Re: [Python-ideas] Python docs page: In what ways is None special

2018-07-26 Thread Chris Angelico
On Fri, Jul 27, 2018 at 9:20 AM, Michael Selik wrote: > On Mon, Jul 23, 2018 at 2:03 AM Jonathan Fine wrote: >> >> Thank you for your attention. What have I missed? > > > None and a few other things are special-cased by CPython. The compiler won't > bother to write bytecode instructions when an i

Re: [Python-ideas] Python docs page: In what ways is None special

2018-07-26 Thread Michael Selik
On Mon, Jul 23, 2018 at 2:03 AM Jonathan Fine wrote: > Thank you for your attention. What have I missed? > None and a few other things are special-cased by CPython. The compiler won't bother to write bytecode instructions when an if-statement obviously evaluates false. That might surprise some f

Re: [Python-ideas] Change repr of collections.OrderedDict to be more dict-like

2018-07-26 Thread Jeroen Demeyer
On 2018-07-27 00:50, David Mertz wrote: I often use doctests to verify APIs and behaviors when I update code. I know I'm in a minority and most developers slightly disparage doctests. If it makes you feel better, SageMath development uses only doctests for testing. We have over 30 doctests

Re: [Python-ideas] Change repr of collections.OrderedDict to be more dict-like

2018-07-26 Thread David Mertz
I often use doctests to verify APIs and behaviors when I update code. I know I'm in a minority and most developers slightly disparage doctests. On Thu, Jul 26, 2018, 6:41 PM Michael Selik wrote: > Sounds good to me. It'll make OrderedDict look much nicer at the REPL. > > > On Thu, Jul 26, 2018 a

Re: [Python-ideas] Change repr of collections.OrderedDict to be more dict-like

2018-07-26 Thread Michael Selik
Sounds good to me. It'll make OrderedDict look much nicer at the REPL. On Thu, Jul 26, 2018 at 10:21 AM Terry Reedy wrote: > I am not sure what our repr change policy is, as there is a > back-compatibility issue but I remember there being changes. Given the way different Python prompts feel f

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-26 Thread Abe Dillon
The readability issue isn't just a matter of a new set of symbols to learn. It isn't even that the symbols are used in a non-intuitive way (though that doesn't help). It's not even that the question mark, unlike the dot, is very visually obtrusive (which also doesn't help). It also screws with the

Re: [Python-ideas] Change repr of collections.OrderedDict to be more dict-like

2018-07-26 Thread Terry Reedy
On 7/26/2018 1:21 PM, Terry Reedy wrote: On python-idea,  Miro Hrončok asked today whether we can change the OrderedDict repr from, for instance, OrderedDict([('a', '1'), ('b', '2')]) # to OrderedDict({'a': '1', 'b': '2'}) I am not sure what our repr change policy is, as there is a back-compa

Re: [Python-ideas] Change repr of collections.OrderedDict to be more dict-like

2018-07-26 Thread David Mertz
Repr changes are likely to break doctests, at least. That's not necessarily an absolute "no", but it does raise the bar. On Thu, Jul 26, 2018, 1:22 PM Terry Reedy wrote: > On 7/26/2018 4:12 AM, Miro Hrončok wrote: > > Hi, > > > > now when dicts are sorted, can we change the repr of > > collectio

Re: [Python-ideas] Change repr of collections.OrderedDict to be more dict-like

2018-07-26 Thread Terry Reedy
On 7/26/2018 4:12 AM, Miro Hrončok wrote: Hi, now when dicts are sorted, can we change the repr of collections.OrderedDict to look like dict? I mean from:     OrderedDict([('a', '1'), ('b', '2')]) To:     OrderedDict({'a': '1', 'b': '2'}) I assume the current list-of-tuples repr is ther

Re: [Python-ideas] slice[] to get more complex slices

2018-07-26 Thread Stephan Hoyer
On Mon, Jul 23, 2018 at 4:37 PM David Mertz wrote: > I find pandas.IndexSlice makes a lot of operations easier to spell. As > simple as it is, it's a valuable capability. Rather than every library—or a > number of them anyway—creating the same 4 lines of code with a different > name, it would be

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-26 Thread Kyle Lahnakoski
On 2018-07-25 23:53, David Mertz wrote: > On Wed, Jul 25, 2018, 11:27 PM Chris Angelico > wrote: > > > means that you cannot do this: > > >>> NullCoalesce(spam).nil is None > > This IS fundamentally unfixable in a library. > > > Right now, you can still alway

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-26 Thread Mikhail V
On Thu, Jul 26, 2018 at 5:10 AM, Steven D'Aprano wrote: > On Wed, Jul 25, 2018 at 05:11:08PM -0500, Abe Dillon wrote: >> The problem here is not whether it's explicit. It's about Readability and >> conciseness. Using symbols in place of words almost always harms >> readability in favor of concisen

Re: [Python-ideas] Python-ideas Digest, Vol 140, Issue 169

2018-07-26 Thread James Lu
> I several times wished I could have had a reference to the block of code in a > `with` clause. Could you abstractly describe a real-world example of this? I’d like to hear your use case. > The example for sorted is also kinda twisted. It is, it’s probably a counterexample on how to use it.

Re: [Python-ideas] Python-ideas Digest, Vol 140, Issue 169

2018-07-26 Thread James Lu
> You mean lambda x: lumberjack(15, x) ? Yes, that was my mistake. > However this syntax you allow to write lumberjack(%, 15) which is only > possible with partial using keyword arguments, like lumberjack (y=15) > (given that the second argument is called "y") and in that case I know at > least o

Re: [Python-ideas] As-do statements in Python

2018-07-26 Thread James Lu
> 4 - introducing a new keyword is the hardest thing you can ever ask on > this list. As is already a keyword from with-as and except-as. Perhaps for compatibility “as” is allowed but discouraged as a variable name, and it’s only interpreted as a keyword when followed by an expression and a colo

Re: [Python-ideas] As-do statements/anonymous blocks in python

2018-07-26 Thread Steven D'Aprano
On Thu, Jul 26, 2018 at 02:07:07PM +0200, Michel Desmoulin wrote: > 4 - introducing a new keyword is the hardest thing you can ever ask on > this list. Introducing a new keyword is like falling off a log compared to introducing a new operator. -- Steve _

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-26 Thread Rhodri James
On 25/07/18 23:11, Abe Dillon wrote: The problem here is not whether it's explicit. It's about Readability and conciseness. Using symbols in place of words almost always harms readability in favor of conciseness. value = person.name if person.name else person ITYM value = person.name if pers

Re: [Python-ideas] As-do statements/anonymous blocks in python

2018-07-26 Thread Robert Vanden Eynde
> lumberjack(15, %) > # is equivalent to the expression > lambda x: lumberjack(15, %) You mean lambda x: lumberjack(15, x) ? So you'd want a better syntax for functools.partial, here your example is partial(lumberjack, 15). However this syntax you allow to write lumberjack(%, 15) which is only p

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-26 Thread Rhodri James
On 25/07/18 23:36, David Mertz wrote: The fact that a while bunch have people have commented on this subthread while not recognizing that the semantics of the '?.' and the if blocks are entirely different suggests the operators are but magnets. *Entirely* different? Rubbish. It's more like th

Re: [Python-ideas] As-do statements/anonymous blocks in python

2018-07-26 Thread Michel Desmoulin
I like the concept, and I several times wished I could have had a reference to the block of code in a `with` clause. However, it is unlikely to happen: 1 - Guido restricted lambda to one expression, and this would just be a way around that 2 - This will be tempting to use for callbacks and chain

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-26 Thread Rhodri James
On 26/07/18 05:25, Raymond Hettinger wrote: This PEP is one step further away from Python reading like executable pseudo-code. +1000 -- Rhodri James *-* Kynesim Ltd ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailma

Re: [Python-ideas] As-do statements/anonymous blocks in python

2018-07-26 Thread Rhodri James
On 25/07/18 18:07, James Lu wrote: I'm open to any changes or criticism. ``` import atexit as atexit.register: # ...do various cleanup tasks... print('Goodbye') # is approximately equivalent to => import atexit def _(): # ...do various cleanup tasks... print('Goodbye') atexi

Re: [Python-ideas] Change repr of collections.OrderedDict to be more dict-like

2018-07-26 Thread Grégory Lielens
True, I was not aware of that... But the thread also predict OrderedDict will become very unfrequent, and that's also my impression: we are currently removing our OrderedDict. I expect OrderedDict will be used only in place where the sequential order is a primary characteristic, with key access

Re: [Python-ideas] Change repr of collections.OrderedDict to be more dict-like

2018-07-26 Thread Miro Hrončok
On 26.7.2018 10:24, Grégory Lielens wrote: I would wait a little bit. OrderedDict will probable become a pure synonym for dict, in a few releases, and the repr issue will solve itself, both giving the even simpler/nicer {'a': '1', 'b': '2'} Your proposal expose that dicts are ordered (which th

Re: [Python-ideas] Change repr of collections.OrderedDict to be more dict-like

2018-07-26 Thread Grégory Lielens
I would wait a little bit. OrderedDict will probable become a pure synonym for dict, in a few releases, and the repr issue will solve itself, both giving the even simpler/nicer {'a': '1', 'b': '2'} Your proposal expose that dicts are ordered (which they are, but it's hidden). Once exposed, Orde

[Python-ideas] Change repr of collections.OrderedDict to be more dict-like

2018-07-26 Thread Miro Hrončok
Hi, now when dicts are sorted, can we change the repr of collections.OrderedDict to look like dict? I mean from: OrderedDict([('a', '1'), ('b', '2')]) To: OrderedDict({'a': '1', 'b': '2'}) I assume the current list-of-tuples repr is there so copy pasting the repr to the interprete

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-26 Thread Abe Dillon
> > Do you know what helps readability? *Learning to read* Do you know what helps? *leveraging intuition* If you're going to throw a question mark in there, which by the way, is far more visually intrusive than a '.', then it makes more sense to at least try to use it in a familiar way: v = (a.b)