[Python-3000] Assert syntax change...

Nick Coghlan ncoghlan at gmail.com
Fri Apr 25 06:13:18 CEST 2008


Charles Merriam wrote:
> On Thu, Apr 24, 2008 at 2:01 PM, Guido van Rossum <guido at python.org> wrote:
>> On Thu, Apr 24, 2008 at 1:51 PM, Mikhail Glushenkov
>>>  Why not make ``assert`` a built-in function then?
>>  Because then it can't be disabled by the compiler in -O mode.
> 
> A reasonable conclusion, but needs better reasoning.  One could
> certainly do an:
>     assert_stmt        ::=     "assert" (expression ["," expression])
> and implement it, when there isn't a -O, as:
>     __assert__(expression, message=None)  # built-in

Hmm, having an __assert__ builtin might be nice regardless - easier to 
have assertions in test suites that are executed regardless of -0, 
instead of every different Python test suite having to include its own 
function to wrap 'raise AssertionError(message)'.

Independently of that, changing assert to allow surrounding parentheses 
(similar to the name list in a from module import name-list style import 
statement) would also be convenient for longer expressions or error 
messages.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-3000 mailing list