Re: [Python-ideas] PEP 572: Statement-Local Name Bindings, take three!

2018-03-26 Thread Tim Peters
[Guido] > ... > Not so fast. There's a perfectly reasonable alternative to sublocal scopes > -- just let it assign to a local variable in the containing scope. That's > the same as what Python does for for-loop variables. That's certainly what I would _expect_ if I never read the docs,

Re: [Python-ideas] PEP 572: Statement-Local Name Bindings, take three!

2018-03-26 Thread Steven D'Aprano
On Mon, Mar 26, 2018 at 03:33:52PM +0100, Rhodri James wrote: > While my crystal ball is cloudy, I can well imagine beginners becoming > very confused over which symbol to use in which circumstance, and a lot > of swearing when: > > x := f() > if (y = g(x)) is not None: > h(y) > >

Re: [Python-ideas] Fixing class scope brainstorm

2018-03-26 Thread Guido van Rossum
On Mon, Mar 26, 2018 at 6:33 AM, Nick Coghlan wrote: > On 26 March 2018 at 01:50, Guido van Rossum wrote: > > In the PEP 572 threads there's some grumbling about class scopes. > > > > Here's a random brainstorm. How about we change the scoping rules so that

Re: [Python-ideas] In-place assignment for "boolean or"?

2018-03-26 Thread Rob Cliffe via Python-ideas
On 26/03/2018 13:48, Cammil Taank wrote: Hi, I find a common idiom in Python is: x = x or 'some other value' This is highly reminiscent of the problem inplace operators solve. Would it be a good idea to consider an inplace operator for this, perhaps: x or= 'some other value' ? Thanks,

Re: [Python-ideas] PEP 572: Statement-Local Name Bindings, take three!

2018-03-26 Thread Rob Cliffe via Python-ideas
On 26/03/2018 16:57, Guido van Rossum wrote: On Mon, Mar 26, 2018 at 7:57 AM, Nick Coghlan > wrote: On 26 March 2018 at 14:34, Guido van Rossum > wrote: > Not so fast. There's a perfectly

Re: [Python-ideas] PEP 572: Statement-Local Name Bindings, take three!

2018-03-26 Thread Guido van Rossum
On Mon, Mar 26, 2018 at 7:57 AM, Nick Coghlan wrote: > On 26 March 2018 at 14:34, Guido van Rossum wrote: > > Not so fast. There's a perfectly reasonable alternative to sublocal > scopes > > -- just let it assign to a local variable in the containing scope.

Re: [Python-ideas] PEP 572: Statement-Local Name Bindings, take three!

2018-03-26 Thread Nick Coghlan
On 26 March 2018 at 14:34, Guido van Rossum wrote: > Not so fast. There's a perfectly reasonable alternative to sublocal scopes > -- just let it assign to a local variable in the containing scope. That's > the same as what Python does for for-loop variables. Note that for >

Re: [Python-ideas] In-place assignment for "boolean or"?

2018-03-26 Thread Rhodri James
On 26/03/18 13:48, Cammil Taank wrote: Hi, I find a common idiom in Python is: x = x or 'some other value' I believe this is a historic idiom from back before the ternary operator was added to Python: x = x if x else 'some other value' though honestly both of those are poor ways of

Re: [Python-ideas] In-place assignment for "boolean or"?

2018-03-26 Thread David Mertz
I actually HAVE used this idiom moderately often. But unless you use overly long names, the current spelling is no trouble at all. In fact, it's not clear why your function is spelled as it is rather than with boolean shortcutting (assuming you like the shortcutting aesthetically). On Mon, Mar

Re: [Python-ideas] In-place assignment for "boolean or"?

2018-03-26 Thread Paul Moore
See https://www.python.org/dev/peps/pep-0505/ On 26 March 2018 at 14:56, Cammil Taank wrote: > Given the arguments you've raised, I am now inclined to agree with you. > > However, for completeness of the discussion, I want to indicate the primary > intended use case: > >

Re: [Python-ideas] PEP 572: Statement-Local Name Bindings, take three!

2018-03-26 Thread Rhodri James
On 26/03/18 02:24, Guido van Rossum wrote: I gotta say I'm warming up to := in preference over 'as',*if* we're going to do this at all (not a foregone conclusion at all). I have the usual objection to glyphs (hard to look up or get help on), but ":=" raises two issues all of its own. * On

Re: [Python-ideas] In-place assignment for "boolean or"?

2018-03-26 Thread Steven D'Aprano
On Mon, Mar 26, 2018 at 01:48:34PM +0100, Cammil Taank wrote: > Hi, > > I find a common idiom in Python is: > > x = x or 'some other value' I don't find it very common. I don't think I've ever used it or seen it. I've occasionally used: spam = eggs or 'something' but mostly I use:

Re: [Python-ideas] Fixing class scope brainstorm

2018-03-26 Thread Nick Coghlan
On 26 March 2018 at 01:50, Guido van Rossum wrote: > In the PEP 572 threads there's some grumbling about class scopes. > > Here's a random brainstorm. How about we change the scoping rules so that > only functions defined with 'def' (or inside one of those) cannot see the >

[Python-ideas] In-place assignment for "boolean or"?

2018-03-26 Thread Cammil Taank
Hi, I find a common idiom in Python is: x = x or 'some other value' This is highly reminiscent of the problem inplace operators solve. Would it be a good idea to consider an inplace operator for this, perhaps: x or= 'some other value' ? Thanks, Cammil

Re: [Python-ideas] PEP 572: Statement-Local Name Bindings, take three!

2018-03-26 Thread Steven D'Aprano
On Mon, Mar 26, 2018 at 02:42:32PM +0300, Kirill Balunov wrote: > I was also thinking about `<-` variant (but with a Haskell in mind), but > with the current Python rules, it seems that it does not fit: Ah, of course not, the dreaded unary operator strikes again! (I was just chatting with Chris

Re: [Python-ideas] PEP 572: Statement-Local Name Bindings, take three!

2018-03-26 Thread Kirill Balunov
2018-03-26 14:18 GMT+03:00 Steven D'Aprano : > That was probably my response to Nick: > > https://mail.python.org/pipermail/python-ideas/2018-March/049472.html > > I compared four possible choices: > > target = default if (expression as name) is None else name >

Re: [Python-ideas] PEP 572: Statement-Local Name Bindings, take three!

2018-03-26 Thread Steven D'Aprano
On Mon, Mar 26, 2018 at 11:14:43AM +0300, Kirill Balunov wrote: > Hi Chris, would you mind to add this syntactic form `(expr -> var)` to > alternative syntax section, with the same semantics as `(expr as var)`. It > seems to me that I've seen this form previously in some thread (can't find >

Re: [Python-ideas] PEP 572 version 2: Statement-Local Name Bindings

2018-03-26 Thread Christoph Groth
Nick Coghlan wrote: > On 25 March 2018 at 22:44, Christoph Groth wrote: > > I think that it's a helpful guideline to imagine what the ideal > > behavior should be if we were not constrained by backwards > > compatibility, and then try to follow it. In the case at hand,

Re: [Python-ideas] PEP 572: Statement-Local Name Bindings, take three!

2018-03-26 Thread Chris Angelico
On Mon, Mar 26, 2018 at 7:14 PM, Kirill Balunov wrote: > Hi Chris, would you mind to add this syntactic form `(expr -> var)` to > alternative syntax section, with the same semantics as `(expr as var)`. It > seems to me that I've seen this form previously in some thread

[Python-ideas] Generalized version of contextlib.close

2018-03-26 Thread Roberto Martínez
Hi, sometimes I need to use contextlib.close but over methods with a different name, for example stop(), halt(), etc. For those cases I have to write my own contextlib.close specialized version with a hard-coded method name. I think adding a "method" argument to contextlib.close can be very

Re: [Python-ideas] PEP 572: Statement-Local Name Bindings, take three!

2018-03-26 Thread Kirill Balunov
Hi Chris, would you mind to add this syntactic form `(expr -> var)` to alternative syntax section, with the same semantics as `(expr as var)`. It seems to me that I've seen this form previously in some thread (can't find where), but it does not appear in alt. syntax section. As for me this form