[Python-3000] Assert syntax change...

Guido van Rossum guido at python.org
Thu Apr 24 20:37:58 CEST 2008


I sympathize with the sentiment, but 'as' is the wrong keyword; there
is no assignment to the thing on its right hand side like there is in
all other places where it is used in the syntax (import-as, with-as,
except-as).

Also, have you actually tried this in 3.0? It prints a nice
SytaxWarning message, which IMO is enough.

--Guido

On Thu, Apr 24, 2008 at 2:27 AM, Charles Merriam
<charles.merriam at gmail.com> wrote:
> Hello All,
>
>  I expect it is far to late for this, and I still wanted to make the issue known.
>
>  The assert statement is one of the few remaining Python statements
>  where it (1) does not use parenthesis and (2) takes multiple
>  arguments.  This leads to the common, hard to detect, programming
>  error:
>       assert(rarelyHappens  > 0 , "Hyperdrive component needs replacement!")
>  which is equivalent to:
>       assert True
>  because the programmer forgot to remove parenthesis for assert statements.
>
>  It would be great to change assert from:
>      assert_stmt        ::=     "assert" expression ["," expression]
>  To:
>      assert_stmt        ::=     "assert" expression ["as" expression]
>
>  Which would make only one way to make an assert statement.
>
>  + One less exception to remember
>  + Fewer "fail silently" errors
>  + One less place where commas outside parenthesis are used.
>  (try/except and print just got fixed).
>  - Way too late:  I wish I had noticed months ago.
>  - Need to patch 2to3, documentation, etc.
>
>  There may be a problem in tuples evaluating as expressions with this
>  naive fix; it's unclear to
>  my little brain if a bare expression_list can be reached from
>  expression.  That is, would
>   assert "tuple","implied" as "Message"
>  or
>   assert neverHappen > 0, "Programmer used 2.5 syntax here"
>  be valid statements?
>
>  In summary, I know that the current assert syntax is wrong.  I know
>  what it should look like.
>  I do not know if the implementation details of parenthesized tuples
>  make this difficult.   I
>  should have noticed it a year ago.
>
>  Charles Merriam
>  _______________________________________________
>  Python-3000 mailing list
>  Python-3000 at python.org
>  http://mail.python.org/mailman/listinfo/python-3000
>  Unsubscribe: http://mail.python.org/mailman/options/python-3000/guido%40python.org
>



-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list