title: design of python: why is assert a statement and not a function?
body: <p><strong>In Python, <code>assert</code> is a statement, and not a function. Was this a deliberate decision? Are there any advantages to having <code>assert</code> be a statement (and reserved word) instead of a function?</strong></p>
  
  <p>According to <a href="http://docs.python.org/2/reference/simple_stmts.html#assert" rel="noreferrer">the</a> <a href="http://docs.python.org/3.2/reference/simple_stmts.html#assert" rel="noreferrer">docs</a>, <code>assert expression1, expression2</code> is expanded to</p>
  
  <pre><code>if __debug__:
      if not expression1: raise AssertionError(expression2)
  </code></pre>
  
  <p>The docs also say that "The current code generator emits no code for an assert statement when optimization is requested at compile time." Without knowing the details, it seems like a special case was required to make this possible. But then, a special case could also be used to optimize away calls to an <code>assert()</code> function.</p>
  
  <p>If <code>assert</code> were a function, you could write:</p>
  
  <pre><code>assert(some_long_condition,
         "explanation")
  </code></pre>
  
  <p>But because <code>assert</code> is a statement, the tuple always evaluates to <code>True</code>, and
  you get</p>
  
  <pre><code>SyntaxWarning: assertion is always true, perhaps remove parentheses?
  </code></pre>
  
  <p>The correct way to write it is</p>
  
  <pre><code>assert some_long_condition, \
         "explanation"
  </code></pre>
  
  <p>which is arguably less pretty.</p>