Re: [Python-Dev] more timely detection of unbound locals

2011-05-15 Thread Vinay Sajip
Terry Reedy udel.edu> writes: > I would change this to > "local name 'bob' used before the assignment that makes it a local name" > > Calling names 'variables' is itself a point of confusion. +1 ___ Python-Dev mailing list Python-Dev@python.org http

Re: [Python-Dev] more timely detection of unbound locals

2011-05-10 Thread Fred Drake
On Tue, May 10, 2011 at 6:38 PM, Steven D'Aprano wrote: > I don't know why it was thought necessary to distinguish between them in the > first place. New users almost constantly expressed confusion by NameError when the name was clearly bound at global scope, and a subsequent assignment caused it

Re: [Python-Dev] more timely detection of unbound locals

2011-05-10 Thread Steven D'Aprano
Nick Coghlan wrote: Personally, I would just add "in current scope" to the existing error message for the unbound local case (and potentially collapse the exception hierarchy a bit by setting UnboundLocalError = NameError). -0 That was the case prior to Python 2.0. Reverting is potentially a

Re: [Python-Dev] more timely detection of unbound locals

2011-05-10 Thread Eli Bendersky
> > > # Early reference to local > > > UnboundLocalError: local variable 'bob' referenced before assignment > > > > I would change this to > > "local name 'bob' used before the assignment that makes it a local name" > > > > Calling names 'variables' is itself a point of confusion. > > Yes, your p

Re: [Python-Dev] more timely detection of unbound locals

2011-05-10 Thread R. David Murray
On Tue, 10 May 2011 13:56:58 -0400, Terry Reedy wrote: > On 5/10/2011 10:59 AM, Nick Coghlan wrote: > > On Tue, May 10, 2011 at 11:11 PM, R. David Murray > > wrote: > >> How about: > >> > >> "reference to variable 'y' precedes an assignment that makes it a local > >> variable" > > > > For compar

Re: [Python-Dev] more timely detection of unbound locals

2011-05-10 Thread Terry Reedy
On 5/10/2011 10:59 AM, Nick Coghlan wrote: On Tue, May 10, 2011 at 11:11 PM, R. David Murray wrote: How about: "reference to variable 'y' precedes an assignment that makes it a local variable" For comparison, the error messages I was able to elicit from 2.7 were as follows: # Module level N

Re: [Python-Dev] more timely detection of unbound locals

2011-05-10 Thread R. David Murray
On Wed, 11 May 2011 00:59:08 +1000, Nick Coghlan wrote: > On Tue, May 10, 2011 at 11:11 PM, R. David Murray w= > rote: > > How about: > > > > "reference to variable 'y' precedes an assignment that makes it a local > > variable" > > For comparison, the error messages I was able to elicit from 2.7

Re: [Python-Dev] more timely detection of unbound locals

2011-05-10 Thread Nick Coghlan
On Tue, May 10, 2011 at 11:11 PM, R. David Murray wrote: > How about: > > "reference to variable 'y' precedes an assignment that makes it a local > variable" For comparison, the error messages I was able to elicit from 2.7 were as follows: # Module level NameError: name 'bob' is not defined # F

Re: [Python-Dev] more timely detection of unbound locals

2011-05-10 Thread Eli Bendersky
On Tue, May 10, 2011 at 16:11, R. David Murray wrote: > On Tue, 10 May 2011 08:36:38 +0300, Eli Bendersky > wrote: > > With an unlimited error message length it could make sense to say "Hey, I > > see 'x' may be assigned in this scope, so I mark it local. But this > access > > to 'x' happens befo

Re: [Python-Dev] more timely detection of unbound locals

2011-05-10 Thread R. David Murray
On Tue, 10 May 2011 08:36:38 +0300, Eli Bendersky wrote: > With an unlimited error message length it could make sense to say "Hey, I > see 'x' may be assigned in this scope, so I mark it local. But this access > to 'x' happens before assignment - so ERROR". This isn't realistic, of > course, so I'

Re: [Python-Dev] more timely detection of unbound locals

2011-05-09 Thread Stefan Behnel
[forwarded to the python-ideas list] Stefan ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Re: [Python-Dev] more timely detection of unbound locals

2011-05-09 Thread Eli Bendersky
On Mon, May 9, 2011 at 18:44, Isaac Morland wrote: > On Mon, 9 May 2011, Eli Bendersky wrote: > > x = 5 >>> def foo (): >>> print (x) >>> if bar (): >>> x = 1 >>> print (x) >>> >>> >> I wish you'd annotate this code sample, what do you intend it to >> demonstrate?

Re: [Python-Dev] more timely detection of unbound locals

2011-05-09 Thread Terry Reedy
On 5/9/2011 9:27 AM, Stefan Behnel wrote: Eli Bendersky, 09.05.2011 14:56: It's a known Python gotcha (*) that the following code: x = 5 def foo(): print(x) x = 1 print(x) foo() Will throw: UnboundLocalError: local variable 'x' referenced before assignment On the usage of 'x' in the *first*

Re: [Python-Dev] more timely detection of unbound locals

2011-05-09 Thread Steven D'Aprano
Eli Bendersky wrote: I think you are making an unwarranted assumption about what is "more expected". I presume you are thinking that the expected behaviour is that foo() should: print global x (5) assign 1 to local x print local x (1) If we implemented this change, there would be no more questi

Re: [Python-Dev] more timely detection of unbound locals

2011-05-09 Thread Isaac Morland
On Mon, 9 May 2011, Eli Bendersky wrote: x = 5 def foo (): print (x) if bar (): x = 1 print (x) I wish you'd annotate this code sample, what do you intend it to demonstrate? It probably shows the original complaint even more strongly. As for being a proble

Re: [Python-Dev] more timely detection of unbound locals

2011-05-09 Thread Nick Coghlan
On Tue, May 10, 2011 at 1:06 AM, Eli Bendersky wrote: > It probably shows the original complaint even more strongly. As for being a > problem with the suggested solution, I suppose you're right, although it > doesn't make it much different. Still, before a *possible* assignment to > 'x', it should

Re: [Python-Dev] more timely detection of unbound locals

2011-05-09 Thread Nick Coghlan
On Tue, May 10, 2011 at 1:01 AM, Eli Bendersky wrote: > >> I think you are making an unwarranted assumption about what is "more >> expected". I presume you are thinking that the expected behaviour is that >> foo() should: >> >> print global x (5) >> assign 1 to local x >> print local x (1) >> >> I

Re: [Python-Dev] more timely detection of unbound locals

2011-05-09 Thread Eli Bendersky
> x = 5 > def foo (): >print (x) >if bar (): >x = 1 >print (x) > I wish you'd annotate this code sample, what do you intend it to demonstrate? It probably shows the original complaint even more strongly. As for being a problem with the suggested solution, I

Re: [Python-Dev] more timely detection of unbound locals

2011-05-09 Thread Eli Bendersky
> I think you are making an unwarranted assumption about what is "more > expected". I presume you are thinking that the expected behaviour is that > foo() should: > > print global x (5) > assign 1 to local x > print local x (1) > > If we implemented this change, there would be no more questions abo

Re: [Python-Dev] more timely detection of unbound locals

2011-05-09 Thread Steven D'Aprano
Eli Bendersky wrote: Hi all, It's a known Python gotcha (*) that the following code: x = 5 def foo(): print(x) x = 1 print(x) foo() Will throw: UnboundLocalError: local variable 'x' referenced before assignment I think part of the problem is that UnboundLocalError is a ja

Re: [Python-Dev] more timely detection of unbound locals

2011-05-09 Thread Eric Snow
On May 9, 2011 6:59 AM, "Eli Bendersky" wrote: > > Hi all, > > It's a known Python gotcha (*) that the following code: > > x = 5 > def foo(): > print(x) > x = 1 > print(x) > foo() > > Will throw: > >UnboundLocalError: local variable 'x' referenced before assignment > > On the u

Re: [Python-Dev] more timely detection of unbound locals

2011-05-09 Thread Stefan Behnel
Eli Bendersky, 09.05.2011 14:56: It's a known Python gotcha (*) that the following code: x = 5 def foo(): print(x) x = 1 print(x) foo() Will throw: UnboundLocalError: local variable 'x' referenced before assignment On the usage of 'x' in the *first* print. Recently, whi

Re: [Python-Dev] more timely detection of unbound locals

2011-05-09 Thread Isaac Morland
On Mon, 9 May 2011, Eli Bendersky wrote: It's a known Python gotcha (*) that the following code: x = 5 def foo(): print(x) x = 1 print(x) foo() Will throw: UnboundLocalError: local variable 'x' referenced before assignment On the usage of 'x' in the *first* print. Recently, wh