[Python-bugs-list] [ python-Bugs-476858 ] Assignment to () should be legal
noreply@sourceforge.net
noreply@sourceforge.net
Wed, 31 Oct 2001 12:39:56 -0800
Bugs item #476858, was opened at 2001-10-31 10:07
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=476858&group_id=5470
Category: Parser/Compiler
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Guido van Rossum (gvanrossum)
Assigned to: Nobody/Anonymous (nobody)
Summary: Assignment to () should be legal
Initial Comment:
>From c.l.py:
Currently,
() = x
gives a compile-time error.
This should really be allowed (and require that x is an
empty sequence, of course) as an end case of
(a,b,c) = x # x must be a 3-sequence
(a,b) = x # x must be a 2-sequence
(a,) = x # x must be a 1-sequence
() = x # why can't x be z 0-sequence?
----------------------------------------------------------------------
>Comment By: Skip Montanaro (montanaro)
Date: 2001-10-31 12:39
Message:
Logged In: YES
user_id=44345
I won't try and counter Tim's vote (besides, he's already got Guido's 51% vote to contend with), but just provide an example used in c.l.py. You might have a function that can return a possibly-empty tuple as part of a larger sequence, e.g.:
def contrived(a, *args):
return (len(args), args*a)
(foo, (bar,)) = contrived(1,2,3)
(foo, ()) = contrived(0,1,2)
Some folks view this as useful. I reserve judgement on that. ;-)
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2001-10-31 10:37
Message:
Logged In: YES
user_id=31435
-1. "Assignment statements are used to (re)bind names to
values and to modify attributes or items of mutable
objects" (from the Ref Man). Since the degenerate cases
(don't forget "[] = x" too) don't do that, they're
not "assignment statements" in a meanignful sense; they
would just be a surprising way to spell
if tuple(x):
raise ValueError
That isn't a frequent enough need to deserve special syntax.
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=476858&group_id=5470