Re: [Python-Dev] nonlocal x = value

2010-12-27 Thread Raymond Hettinger

On Dec 25, 2010, at 2:59 AM, Stefan Behnel wrote:

 Hrvoje Niksic, 24.12.2010 09:45:
 On 12/23/2010 10:03 PM, Laurens Van Houtven wrote:
 On Thu, Dec 23, 2010 at 9:51 PM, Georg Brandl wrote:
 Yes and no -- there may not be an ambiguity to the parser, but still to
 the human. Except if you disallow the syntax in any case, requiring
 people to write
 
 nonlocal x = (3, y)
 
 which is then again inconsistent with ordinary assignment statements.
 
 Right -- but (and hence the confusion) I was arguing for not mixing
 global/nonlocal with assignment at all, and instead having nonlocal
 and global only take one or more names. That would (obviously) remove
 any such ambiguity ;-)
 
 I would like to offer the opposing viewpoint: nonlocal x = value is a
 useful shortcut because nonlocal is used in closure callbacks where
 brevity matters.
 
 I doubt that it really matters so much that one line more kills readability. 
 It's still a relatively rare use case after all.
 
 
 The reason nonlocal is introduced is to change the
 variable, so it makes sense that the two can be done in the same line of
 code.

FWIW, I'm entirely opposed to doing an assignment in a nonlocal definition.

* It is easily mis-parsed by human (as shown by Georg's examples).
* It looks very much like an initialization of a local variable in many 
languages,
  but it is not -- the variable has already been initialized in another scope.
* It is not clear how to extend it to multiple variables (which we already 
allow).
* It is entirely unnecessary.  Just add a real assignment on the following line:
 local x
 x = 3, y
* We've had global declarations for a very long time and never needed
   (or wanted) an assignment for it:
global x = 3, y
* The purported use case is rare (at best).  Special cases aren't worth 
breaking the rules.
   And the purported goal (saving one line) isn't much of a payoff.
* The language moratorium is ending but the aversion to non-essential 
   micro-syntax changes persists.
* And, Georg doesn't like it :-)


Raymond
___
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] nonlocal x = value

2010-12-27 Thread Mark Dickinson
On Mon, Dec 27, 2010 at 9:43 AM, Raymond Hettinger
raymond.hettin...@gmail.com wrote:
 FWIW, I'm entirely opposed to doing an assignment in a nonlocal definition.
 [...]

-1 for assignment in nonlocal and global statements from me, too.

Mark
___
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] nonlocal x = value

2010-12-27 Thread Nick Coghlan
On Mon, Dec 27, 2010 at 8:31 PM, Mark Dickinson dicki...@gmail.com wrote:
 On Mon, Dec 27, 2010 at 9:43 AM, Raymond Hettinger
 raymond.hettin...@gmail.com wrote:
 FWIW, I'm entirely opposed to doing an assignment in a nonlocal definition.
 [...]

 -1 for assignment in nonlocal and global statements from me, too.

Indeed. The PEP should be updated to be clear that that part was never
implemented (referencing Raymond's post for the reasons why).

Cheers,
Nick.

-- 
Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
___
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] nonlocal x = value

2010-12-25 Thread Stefan Behnel

Hrvoje Niksic, 24.12.2010 09:45:

On 12/23/2010 10:03 PM, Laurens Van Houtven wrote:

On Thu, Dec 23, 2010 at 9:51 PM, Georg Brandl wrote:

Yes and no -- there may not be an ambiguity to the parser, but still to
the human. Except if you disallow the syntax in any case, requiring
people to write

nonlocal x = (3, y)

which is then again inconsistent with ordinary assignment statements.


Right -- but (and hence the confusion) I was arguing for not mixing
global/nonlocal with assignment at all, and instead having nonlocal
and global only take one or more names. That would (obviously) remove
any such ambiguity ;-)


I would like to offer the opposing viewpoint: nonlocal x = value is a
useful shortcut because nonlocal is used in closure callbacks where
brevity matters.


I doubt that it really matters so much that one line more kills 
readability. It's still a relatively rare use case after all.




The reason nonlocal is introduced is to change the
variable, so it makes sense that the two can be done in the same line of
code.


But still, this is just a special case. If the variable is changed more 
than once, you'd end up with one assignment with nonlocal and one without. 
This just adds to the growing list of code inconsistencies presented in 
this thread.




As for global x = value being disallowed, I have been annoyed at times with
that, so that sounds like a good argument to change both.

Requiring the parentheses for tuple creation sounds like a good compromise
for resolving the ambiguity, consistent with similar limitations of the
generator expression syntax.


Why introduce such a pitfall for coders here? Require doesn't mean the 
parser can enforce it. If it's not there, it just means something else, so 
it's up to the coder to get it right. The exact same kind of situation that 
was fixed for the except syntax in Python 3.


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] nonlocal x = value

2010-12-24 Thread Hrvoje Niksic

On 12/23/2010 10:03 PM, Laurens Van Houtven wrote:

On Thu, Dec 23, 2010 at 9:51 PM, Georg Brandlg.bra...@gmx.net  wrote:

 Yes and no -- there may not be an ambiguity to the parser, but still to
 the human.  Except if you disallow the syntax in any case, requiring
 people to write

 nonlocal x = (3, y)

 which is then again inconsistent with ordinary assignment statements.


Right -- but (and hence the confusion) I was arguing for not mixing
global/nonlocal with assignment at all, and instead having nonlocal
and global only take one or more names. That would (obviously) remove
any such ambiguity ;-)


I would like to offer the opposing viewpoint: nonlocal x = value is a 
useful shortcut because nonlocal is used in closure callbacks where 
brevity matters.  The reason nonlocal is introduced is to change the 
variable, so it makes sense that the two can be done in the same line of 
code.


As for global x = value being disallowed, I have been annoyed at times 
with that, so that sounds like a good argument to change both.


Requiring the parentheses for tuple creation sounds like a good 
compromise for resolving the ambiguity, consistent with similar 
limitations of the generator expression syntax.

___
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] nonlocal x = value

2010-12-23 Thread Georg Brandl
Am 22.12.2010 23:11, schrieb Laurens Van Houtven:
 On Sat, Dec 18, 2010 at 1:12 PM, Georg Brandl g.bra...@gmx.net wrote:
 Am 17.12.2010 17:52, schrieb Laurens Van Houtven:
 +1 for throwing it out of the PEP. Assignment is a thing,
 nonlocal/global is a thing, don't mix them up :) (That in addition to
 the grammar cleanliness argument Stephan already made)

 The trouble is what to make of

 nonlocal x = 3, y

 Is it two nonlocal declarations or one with a tuple assignment?

 Georg
 
 I'm not sure I understand. Isn't that another reason to throw it out?
 If you don't allow such assignments, there can't be any ambiguity,
 right? (Or am I missing something?)

Yes and no -- there may not be an ambiguity to the parser, but still to
the human.  Except if you disallow the syntax in any case, requiring
people to write

nonlocal x = (3, y)

which is then again inconsistent with ordinary assignment statements.

Georg

___
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] nonlocal x = value

2010-12-23 Thread Laurens Van Houtven
On Thu, Dec 23, 2010 at 9:51 PM, Georg Brandl g.bra...@gmx.net wrote:
 Yes and no -- there may not be an ambiguity to the parser, but still to
 the human.  Except if you disallow the syntax in any case, requiring
 people to write

 nonlocal x = (3, y)

 which is then again inconsistent with ordinary assignment statements.

 Georg

Right -- but (and hence the confusion) I was arguing for not mixing
global/nonlocal with assignment at all, and instead having nonlocal
and global only take one or more names. That would (obviously) remove
any such ambiguity ;-)

cheers
lvh
___
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] nonlocal x = value

2010-12-23 Thread Georg Brandl
Am 23.12.2010 22:03, schrieb Laurens Van Houtven:
 On Thu, Dec 23, 2010 at 9:51 PM, Georg Brandl g.bra...@gmx.net wrote:
 Yes and no -- there may not be an ambiguity to the parser, but still to
 the human.  Except if you disallow the syntax in any case, requiring
 people to write

 nonlocal x = (3, y)

 which is then again inconsistent with ordinary assignment statements.

 Georg
 
 Right -- but (and hence the confusion) I was arguing for not mixing
 global/nonlocal with assignment at all, and instead having nonlocal
 and global only take one or more names. That would (obviously) remove
 any such ambiguity ;-)

Oh yes, I see -- not sure why I worded it like I did.  I just wanted to
reiterate the most obvious problematic point to people who hadn't followed
the earlier discussions about it.  Sorry.

Georg

___
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] nonlocal x = value

2010-12-22 Thread Laurens Van Houtven
On Sat, Dec 18, 2010 at 1:12 PM, Georg Brandl g.bra...@gmx.net wrote:
 Am 17.12.2010 17:52, schrieb Laurens Van Houtven:
 +1 for throwing it out of the PEP. Assignment is a thing,
 nonlocal/global is a thing, don't mix them up :) (That in addition to
 the grammar cleanliness argument Stephan already made)

 The trouble is what to make of

 nonlocal x = 3, y

 Is it two nonlocal declarations or one with a tuple assignment?

 Georg

I'm not sure I understand. Isn't that another reason to throw it out?
If you don't allow such assignments, there can't be any ambiguity,
right? (Or am I missing something?)

lvh
___
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] nonlocal x = value

2010-12-22 Thread Terry Reedy

On 12/22/2010 5:11 PM, Laurens Van Houtven wrote:

On Sat, Dec 18, 2010 at 1:12 PM, Georg Brandlg.bra...@gmx.net  wrote:

Am 17.12.2010 17:52, schrieb Laurens Van Houtven:

+1 for throwing it out of the PEP. Assignment is a thing,
nonlocal/global is a thing, don't mix them up :) (That in addition to
the grammar cleanliness argument Stephan already made)


The trouble is what to make of

nonlocal x = 3, y

Is it two nonlocal declarations or one with a tuple assignment?

Georg


I'm not sure I understand. Isn't that another reason to throw it out?


I am sure he meant it to be, and I agree. We lived without
global x = 3, y
all these years.


If you don't allow such assignments, there can't be any ambiguity,
right? (Or am I missing something?)



--
Terry Jan Reedy

___
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] nonlocal x = value

2010-12-18 Thread Georg Brandl
Am 17.12.2010 17:52, schrieb Laurens Van Houtven:
 +1 for throwing it out of the PEP. Assignment is a thing,
 nonlocal/global is a thing, don't mix them up :) (That in addition to
 the grammar cleanliness argument Stephan already made)

The trouble is what to make of

nonlocal x = 3, y

Is it two nonlocal declarations or one with a tuple assignment?

Georg

___
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] nonlocal x = value

2010-12-17 Thread Benjamin Peterson
2010/12/17 Stefan Behnel stefan...@behnel.de:
 Hi,

 it seems that Py3 doesn't support setting a nonlocal value as part of the
 nonlocal command

    Python 3.2a4+ (py3k:86480, Nov 16 2010, 16:43:22)
    [GCC 4.4.3] on linux2
    Type help, copyright, credits or license for more information.
     def x():
    ...   y = 5
    ...   def f():
    ...     nonlocal y = 6
      File stdin, line 4
        nonlocal y = 6
                   ^
    SyntaxError: invalid syntax

 even though the PEP clearly describes this feature.

 http://www.python.org/dev/peps/pep-3104/#proposed-solution

 Either the PEP or the implementation should be updated. Personally, I think
 the PEP should be changed as I think that the syntax complicates the grammar
 more than it's worth. Also, the moratorium applies here, given that Py3.1
 does not implement this.

 Comments?

There's a issue and a patch for this somewhere. I personally don't
care; it's not too painful to write two lines.



-- 
Regards,
Benjamin
___
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] nonlocal x = value

2010-12-17 Thread Laurens Van Houtven
+1 for throwing it out of the PEP. Assignment is a thing,
nonlocal/global is a thing, don't mix them up :) (That in addition to
the grammar cleanliness argument Stephan already made)

cheers
lvh.
___
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] nonlocal x = value

2010-12-17 Thread Alexander Belopolsky
On Fri, Dec 17, 2010 at 11:52 AM, Laurens Van Houtven l...@laurensvh.be wrote:
 +1 for throwing it out of the PEP. Assignment is a thing,
 nonlocal/global is a thing, don't mix them up :) (That in addition to
 the grammar cleanliness argument Stephan already made)

Another +1 for the same reasons.  Also, since global does not allow
assignment, neither should nonlocal.
___
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] nonlocal x = value

2010-12-17 Thread Benjamin Peterson
2010/12/17 Alexander Belopolsky alexander.belopol...@gmail.com:
 On Fri, Dec 17, 2010 at 11:52 AM, Laurens Van Houtven l...@laurensvh.be 
 wrote:
 +1 for throwing it out of the PEP. Assignment is a thing,
 nonlocal/global is a thing, don't mix them up :) (That in addition to
 the grammar cleanliness argument Stephan already made)

 Another +1 for the same reasons.  Also, since global does not allow
 assignment, neither should nonlocal.

Note that the PEP stated that global would also be extended.



-- 
Regards,
Benjamin
___
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] nonlocal x = value

2010-12-17 Thread Alexander Belopolsky
On Fri, Dec 17, 2010 at 12:33 PM, Benjamin Peterson benja...@python.org wrote:
..
 Another +1 for the same reasons.  Also, since global does not allow
 assignment, neither should nonlocal.

 Note that the PEP stated that global would also be extended.

I missed that, so for future reference, the PEP says:


A shorthand form is also permitted, in which nonlocal is prepended to
an assignment or augmented assignment:

nonlocal x = 3
The above has exactly the same meaning as nonlocal x; x = 3. (Guido
supports a similar form of the global statement.)


and refers to Guido's post at

http://mail.python.org/pipermail/python-3000/2006-November/004166.html

In any case, the relevant issue is

http://bugs.python.org/issue4199

and it should probably be marked as after moratorium.  Meanwhile an
implementation status note can be added to the PEP to avoid this issue
being brought up again.
___
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


[Python-Dev] nonlocal x = value

2010-12-16 Thread Stefan Behnel

Hi,

it seems that Py3 doesn't support setting a nonlocal value as part of the 
nonlocal command


Python 3.2a4+ (py3k:86480, Nov 16 2010, 16:43:22)
[GCC 4.4.3] on linux2
Type help, copyright, credits or license for more information.
 def x():
...   y = 5
...   def f():
... nonlocal y = 6
  File stdin, line 4
nonlocal y = 6
   ^
SyntaxError: invalid syntax

even though the PEP clearly describes this feature.

http://www.python.org/dev/peps/pep-3104/#proposed-solution

Either the PEP or the implementation should be updated. Personally, I think 
the PEP should be changed as I think that the syntax complicates the 
grammar more than it's worth. Also, the moratorium applies here, given that 
Py3.1 does not implement this.


Comments?

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