[Python-3000] Assert syntax change...

"Martin v. Löwis" martin at v.loewis.de
Fri Apr 25 20:09:14 CEST 2008


> A reasonable conclusion, but needs better reasoning.  One could
> certainly do an:
>     assert_stmt        ::=     "assert" (expression ["," expression])

I don't understand that change. Adding parentheses in the EBNF
merely adds grouping in the grammar; it doesn't actually change the
syntax.

Perhaps you meant

   assert_stmt ::= "assert" "(" expression ["," expression] ")"

> and implement it, when there isn't a -O, as:
>     __assert__(expression, message=None)  # built-in

For the issue under discussion, this is unrelated.
In any case, this would be another incompatible change.

Python 2.4.5 (#2, Mar 12 2008, 00:15:51)
[GCC 4.2.3 (Debian 4.2.3-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
py> assert 3>0, a
py>

Here, the "message" expression isn't evaluated unless the assertion
fails. With your change, it would be evaluated.

Regards,
Martin


More information about the Python-3000 mailing list