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.

classification
Title: io.UnsupportedOperation.__new__(io.UnsupportedOperation) fails
Type: behavior Stage: patch review
Components: Distutils2 Versions: Python 3.3
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: eric.araujo Nosy List: Mark.Shannon, alexis, benjamin.peterson, eric.araujo, larry, ncoghlan, pitrou, tarek
Priority: normal Keywords: patch

Created on 2012-03-09 12:39 by Mark.Shannon, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
io_new.patch Mark.Shannon, 2012-03-09 12:39 review
Messages (2)
msg155227 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2012-03-09 12:39
>>> 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.
msg164849 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2012-07-07 14:03
>>> io.UnsupportedOperation.__new__(io.UnsupportedOperation)
behaves correctly now (rev d9c98730e2e8)

This bug was (I believe) caused somehow by an error in OSError_new() which did not initialize self->args if OSError_init() was not called.

Here is a crash which exploited the lack of initialization:
(Works on rev 2a142141e5fd)

>>> class C(ValueError, OSError):pass
... 
>>> c = OSError.__new__(C)
>>> str(c)
Segmentation fault (core dumped)

This has already been fixed, so I'm closing this issue.
History
Date User Action Args
2022-04-11 14:57:27adminsetgithub: 58449
2012-07-07 14:48:49benjamin.petersonsetresolution: fixed -> out of date
2012-07-07 14:03:22Mark.Shannonsetstatus: open -> closed

assignee: eric.araujo
components: + Distutils2, - Interpreter Core

nosy: + alexis, tarek
messages: + msg164849
resolution: fixed
2012-07-07 09:51:20pitrousetnosy: + ncoghlan
2012-07-07 09:43:03larrysetnosy: + larry
2012-03-22 04:57:07eric.araujosetnosy: + pitrou
2012-03-10 02:28:24eric.araujosetnosy: + eric.araujo
2012-03-10 00:26:34terry.reedysetstage: patch review
versions: + Python 3.3
2012-03-09 14:35:00pitrousetnosy: + benjamin.peterson
2012-03-09 12:39:15Mark.Shannoncreate