[Python-Dev] Exceptions and slicing

Brett Cannon brett at python.org
Wed Sep 20 22:04:49 CEST 2006


On 9/20/06, Thomas Heller <theller at python.net> wrote:
>
> Brett Cannon schrieb:
> > On 9/20/06, Thomas Heller <theller at python.net> wrote:
> >>
> >> Is it an oversight that exception instances do no longer support
> >> slicing in Python 2.5?
> >>
> >> This code works in 2.4, but no longer in 2.5:
> >>
> >> try:
> >>     open("", "r")
> >> except IOError, details:
> >>     print details[:]
> >
> >
> > Technically, yes.  There is no entry in the sq_slice field for the
> > PySequenceMethods struct.  Although you can get to the list of arguments
> by
> > going through the 'args' attribute if you need a quick fix.
>
> Well, Nick Coghlan pointed out in private email:
>
> >> According to PEP 352 it should have at most been deprecated along with
> the
> >> rest of Exception.__getitem__:
> >>
> >> "This also means providing a __getitem__ method is unneeded for
> exceptions and
> >> thus will be deprecated as well."


Right, the deprecation is not scheduled until Python 2.9 for __getitem__ so
it was a regression problem (was never a test for it before PEP 352 was
written).  The fix is now in so your code should work again from a trunk
checkout.  I will backport when the freeze is raised.

-Brett
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-dev/attachments/20060920/5e51126c/attachment.html 


More information about the Python-Dev mailing list