except clause syntax question
Mel Wilson
mwilson at the-wire.com
Tue Jan 31 23:39:38 EST 2012
Chris Angelico wrote:
> On Wed, Feb 1, 2012 at 9:03 AM, Duncan Booth
> <duncan.booth at invalid.invalid> wrote:
>> Abitrarily nested tuples of exceptions cannot contain loops so the code
>> simply needs to walk through the tuples until it finds a match.
>
> Is this absolutely guaranteed? The C API for CPython provides:
> (Py2) http://docs.python.org/c-api/tuple.html#PyTuple_SetItem
> (Py3) http://docs.python.org/dev/c-api/tuple.html#PyTuple_SetItem
>
> which doesn't have massive warnings on it saying "USE THIS ONLY TO
> INITIALIZE A TUPLE" (compare, for instance, _PyTuple_Resize which does
> carry a similar warning). Is the assumption then that we're all
> adults, and that mutating a tuple is like passing a null pointer to an
> API function (aka "loaded gun in proximity to foot")?
Unfortunately, I can't remember the details now, but I once set out to
create a recursive tuple by using the C API, and it turned out then that the
C API went to some lengths to prevent anyone being able to do that. I did
finally do it in some peculiar way, but it wasn't simple. The c.l.python
archives might still have the post where I described it.
Mel.
More information about the Python-list
mailing list