logic behind the assert syntax?

Grant Edwards nobody at nowhere.nohow
Tue Aug 29 10:52:50 EDT 2000


In article <20000829100322.K500 at xs4all.nl>, Thomas Wouters wrote:
>On Tue, Aug 29, 2000 at 01:37:59AM +0200, Niels Diepeveen wrote:
>
>> >>> assert 0 == 1, 2, 3
>> SyntaxError: invalid syntax
>
>> Not really what I'd expect, going by the language reference.
>
>Hmm.
>assert_statement: "assert" expression ["," expression]
>
>That's pretty obvious to me: it only takes a single comma. And note that the
>last expressions is an 'expression', *not* an expression_list.

One might expect that "2,3" is an expression whose value is a tuple.
But it isn't, so the assert example isn't legal.  "(2,3)" _is_ an expression,
so the following _is_ legal:
  assert 0==1, (2,3)

It's entirely moot (and perhaps obvious), but I'm going to say it anyway...

What I think Python syntax needs is another set of delimiters to be used for
tuples. Then it would be completely plain that the commas in "foo(a,b,c)"
and "print a,b,c" are not creating tuples, but are part of the syntax for
the statements.

It would also be more obvious that
  assert 0==1,2,3
isn't legal.

One possiblilty would be to use [] and {} for lists and tuples, and come up
with something else for dictionaries.  Perhaps my programs are unusual, but
I have way more literal tuples than I do literal dictionaries. Using a
multi-character delimiter for dicttionaries wouldn't irk me too much.

Alternatively, one could use an operator other than "," for constructing
tuples -- but I like the delimiter method better.  I'm sure there are
disadvantages to the tuple-delimiter scheme of which I haven't thought.

-- 
Grant Edwards                   grante             Yow!  Hello. I know
                                  at               the divorce rate among
                               visi.com            unmarried Catholic Alaskan
                                                   females!!



More information about the Python-list mailing list