Re: variable scope in try ... EXCEPT block.

2018-07-13 Thread Chris Angelico
On Fri, Jul 13, 2018 at 10:43 PM, Ed Kellett wrote: > On 2018-07-12 18:00, Chris Angelico wrote: >> What do you mean by "fix"? Make the 'x' bind eagerly? That would break >> basically every other use of closures. > > No. I mean make each x a new variable--closures would work as before, > for-loops

Re: variable scope in try ... EXCEPT block.

2018-07-13 Thread Ed Kellett
On 2018-07-12 18:00, Chris Angelico wrote: > What do you mean by "fix"? Make the 'x' bind eagerly? That would break > basically every other use of closures. No. I mean make each x a new variable--closures would work as before, for-loops would change. If we have subscopes, it seems natural that ent

Re: variable scope in try ... EXCEPT block.

2018-07-12 Thread Chris Angelico
On Fri, Jul 13, 2018 at 2:44 PM, wrote: > On Thursday, July 12, 2018 at 7:16:48 PM UTC-4, Chris Angelico wrote: >> Not sure, but here's a simpler implementation: >> >> except Exception as .err.0: >> print(.err.0) >> .err.0 = None >> del .err.0 >> >> In other words, exactly the same as

Re: variable scope in try ... EXCEPT block.

2018-07-12 Thread codewizard
On Thursday, July 12, 2018 at 7:16:48 PM UTC-4, Chris Angelico wrote: > On Fri, Jul 13, 2018 at 8:10 AM Igor wrote: > > On Thursday, July 12, 2018 at 5:45:52 AM UTC-4, Ben Bacarisse wrote: > >> aleiphoenix writes: > >> > >> [snip] > >> > >> When an exception has been assigned using as target, it

Re: variable scope in try ... EXCEPT block.

2018-07-12 Thread aleiphoenix
On Thursday, July 12, 2018 at 5:45:52 PM UTC+8, Ben Bacarisse wrote: > > Yes, it's intentional, but it's not exactly a scope. In > > https://docs.python.org/3/reference/compound_stmts.html#try > > -- > Ben. Thank you for the reply. Never thought of this kind of problem in Python3. On Thurs

Re: variable scope in try ... EXCEPT block.

2018-07-12 Thread Chris Angelico
On Fri, Jul 13, 2018 at 8:10 AM, wrote: > On Thursday, July 12, 2018 at 5:45:52 AM UTC-4, Ben Bacarisse wrote: >> aleiphoenix writes: >> >> [snip] >> >> When an exception has been assigned using as target, it is cleared at >> the end of the except clause. This is as if >> >> except E as N:

Re: variable scope in try ... EXCEPT block.

2018-07-12 Thread Ben Bacarisse
Just word on quoting... codewiz...@gmail.com writes: > On Thursday, July 12, 2018 at 5:45:52 AM UTC-4, Ben Bacarisse wrote: >> >> [snip] You cut everything I wrote. What you left is what I quoted from the Python documentation. In fairness to the authors you should probably have cut the attrib

Re: variable scope in try ... EXCEPT block.

2018-07-12 Thread codewizard
On Thursday, July 12, 2018 at 5:45:52 AM UTC-4, Ben Bacarisse wrote: > aleiphoenix writes: > > [snip] > > When an exception has been assigned using as target, it is cleared at > the end of the except clause. This is as if > > except E as N: > foo > > was translated to > > excep

Re: variable scope in try ... EXCEPT block.

2018-07-12 Thread Chris Angelico
On Thu, Jul 12, 2018 at 11:23 PM, Ed Kellett wrote: > Could we fix: > > for x in something: > blah(lambda a: a + x) > > while we're at it? What do you mean by "fix"? Make the 'x' bind eagerly? That would break basically every other use of closures. ChrisA -- https://mail.python.org/mailma

Re: variable scope in try ... EXCEPT block.

2018-07-12 Thread Ed Kellett
On 2018-07-12 14:03, Chris Angelico wrote: > Dealing with reference cycles is generally done *periodically* rather > than immediately (CPython disposes of unreferenced objects immediately > upon last deref). You can avoid having a dedicated cycle detection > pass by using a mark-and-sweep GC, but t

Re: variable scope in try ... EXCEPT block.

2018-07-12 Thread Chris Angelico
On Thu, Jul 12, 2018 at 10:31 PM, Ed Kellett wrote: > On 2018-07-12 10:59, Steven D'Aprano wrote: >> On Thu, 12 Jul 2018 01:37:24 -0700, aleiphoenix wrote: >> >>> My question is, does except ... as ... create a new scope from outer >>> block, causing 'err' be hidden from outer scope? Is this inten

Re: variable scope in try ... EXCEPT block.

2018-07-12 Thread Ed Kellett
On 2018-07-12 10:59, Steven D'Aprano wrote: > On Thu, 12 Jul 2018 01:37:24 -0700, aleiphoenix wrote: > >> My question is, does except ... as ... create a new scope from outer >> block, causing 'err' be hidden from outer scope? Is this intentional? > > No, it is not a new scope, and yes, it is int

Re: variable scope in try ... EXCEPT block.

2018-07-12 Thread Steven D'Aprano
On Thu, 12 Jul 2018 01:37:24 -0700, aleiphoenix wrote: > My question is, does except ... as ... create a new scope from outer > block, causing 'err' be hidden from outer scope? Is this intentional? No, it is not a new scope, and yes, it is intentional. It's a nasty hack, but a *necessary* nasty

Re: variable scope in try ... EXCEPT block.

2018-07-12 Thread Ben Bacarisse
aleiphoenix writes: > suppose following code running with Python-3.4.8 and Python-3.6.5 > > > # -*- coding: utf-8 -*- > > > def hello(): > err = None > print('0: {}'.format(locals())) > try: > b = 2 > print('1: {}'.format(locals())) > raise ValueError() >