[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Assertions that are always true



On May 28, 2012, at 12:33 AM, Jakub Wilk wrote:

>It's a mistake to write
>
>      assert(tilsit, 'Never at the end of the week, sir.')
>
>instead of
>
>      assert tilsit, 'Never at the end of the week, sir.'
>
>The former assertion is always true, and thus no-op. Python >= 2.6 emits a
>SyntaxWarning about this.

Nice catch.  I've seen something similar quite often, but written correctly,
it's a good way to provide meaningful longer assertion messages, without any
ugly backslashes.  The *right* way to write this would be:

    assert tilsit, (
        'Never at the end of the week, sir.')

Cheers,
-Barry


Reply to: