[Python-3000] remove tuple exceptions?

Jim Jewett jimjjewett at gmail.com
Fri Mar 2 22:35:38 CET 2007


What is the reasoning behind allowing the raise of a tuple -- but
really only raising its (recursively) first element?

It seems to have been added (with different spelling) in 1991 (rev
2625) as the only alternative to string exceptions.  (You couldn't
raise a class or instance.)  I assume it was kept for backwards
compatibility.

Were there other reasons, or should this be removed in python 3?

Looking at ceval.c

/* We support the following forms of raise:
...
	   raise <classinstance>, None
...
	   In addition, raise <tuple>, <anything> is the same as
	   raising the tuple's first item (and it better have one!);
	   this rule is applied recursively.
...
/* Next, repeatedly, replace a tuple exception with its first item */
	while (PyTuple_Check(type) && PyTuple_Size(type) > 0) {
		PyObject *tmp = type;
		type = PyTuple_GET_ITEM(type, 0);
		Py_INCREF(type);
		Py_DECREF(tmp);
	}


More information about the Python-3000 mailing list