This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Mark.Shannon
Recipients Mark.Shannon
Date 2012-03-09.12:39:14
SpamBayes Score 9.795336e-07
Marked as misclassified No
Message-id <1331296756.01.0.329340447456.issue14241@psf.upfronthosting.co.za>
In-reply-to
Content
>>> io.UnsupportedOperation.__new__(io.UnsupportedOperation)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: ValueError.__new__(UnsupportedOperation) is not safe, use OSError.__new__()

Looking at the mro of io.UnsupportedOperation
(io.UnsupportedOperation, ValueError, OSError, Exception, BaseException, object'>)

Shows that ValueError.__new__ is getting called, but will not construct 
an instance of a subtype of OSError

Switching the order of ValueError and OSError fixes this error (patch attached), but doesn't fix the underlying problem.

Why doesn't io.UnsupportedOperation() fail, when
UnsupportedOperation.__new__ does?
io.UnsupportedOperation() actually calls OSError.__new__ 
via the internal tp_new slot.
In other words UnsupportedOperation->tp_new != UnsupportedOperation.__new__
This should not happen, it looks like the logic in inherit_special()
in typeobject.c may be faulty.
History
Date User Action Args
2012-03-09 12:39:16Mark.Shannonsetrecipients: + Mark.Shannon
2012-03-09 12:39:16Mark.Shannonsetmessageid: <1331296756.01.0.329340447456.issue14241@psf.upfronthosting.co.za>
2012-03-09 12:39:15Mark.Shannonlinkissue14241 messages
2012-03-09 12:39:15Mark.Shannoncreate