[New-bugs-announce] [issue14241] io.UnsupportedOperation.__new__(io.UnsupportedOperation) fails

Mark Shannon report at bugs.python.org
Fri Mar 9 13:39:16 CET 2012

New submission from Mark Shannon <mark at hotpy.org>:

>>> 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.

components: Interpreter Core
files: io_new.patch
keywords: patch
messages: 155227
nosy: Mark.Shannon
priority: normal
severity: normal
status: open
title: io.UnsupportedOperation.__new__(io.UnsupportedOperation) fails
type: behavior
Added file: http://bugs.python.org/file24768/io_new.patch

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list