"raise (type, value, traceback)" and "raise type, value, traceback"

Ian Kelly ian.g.kelly at gmail.com
Mon May 2 15:32:45 EDT 2011


On Mon, May 2, 2011 at 11:23 AM, Jack Bates <ms419 at freezone.co.uk> wrote:
> Hi, anyone know why these two statements aren't equivalent?
>
> raise (type, value, traceback)
>
> raise type, value, traceback

The latter is the syntax of the raise statement: up to 3 expressions,
separated by commas.

The former has a single expression that evaluates to a tuple.  It's
equivalent to this:

t = (type, value, traceback)
raise t

That it accepts the tuple and raises a value-less expression of type
`type` surprises me.  The docs don't say anything about this, and I
would have expected a TypeError, but it appears to be extracting the
first element of the tuple and using that as the value of the first
expression.



More information about the Python-list mailing list