A small inconsistency in syntax?

Terry Reedy tjreedy at home.com
Fri Oct 26 08:15:36 CEST 2001


"Guido van Rossum" <guido at python.org> wrote in message
news:cp7ktjcbzx.fsf at cj20424-a.reston1.va.home.com...
> Greg Ewing <greg at cosc.canterbury.ac.nz> writes:
> > In the case in question, i.e.
> >
> >    () = ()
> >
> > the patterns clearly do match. And, every name in
> > the LHS has a corresponding value in the RHS. The
> > numbers of both these things happen to be 0, but
> > so what?

> > I think Michael Abbot is quite right. There's no
> > reason this shouldn't be a legitimate, albeit
> > degenerate, case of tuple unpacking.

> FWIW, I agree.  I just never thought of this.
>
> --Guido van Rossum (home page: http://www.python.org/~guido/)

As I understand it, the rule is this:  if item on LHS is tuple rather
than name, then corresponding object on RHS must be a tuple, which
will then be seen as collection rather than object in itself and
consequently unpacked for matching to items within LHS tuple.
Allowing for null matches and applying the rule recursively,

a,() = 1,()

should also be legal, as Abbot also expected.  I can imagine some use
to

() = function()

which I presume would raise exception if function() returned anything
other than ().

Terry J. Reedy










More information about the Python-list mailing list