cpython: d22c99e77768 (original) (raw)

--- a/Lib/test/test_pep3151.py +++ b/Lib/test/test_pep3151.py @@ -12,6 +12,23 @@ from test import support class SubOSError(OSError): pass +class SubOSErrorWithInit(OSError):

+ +class SubOSErrorWithNew(OSError):

+ +class SubOSErrorCombinedInitFirst(SubOSErrorWithInit, SubOSErrorWithNew):

+ +class SubOSErrorCombinedNewFirst(SubOSErrorWithNew, SubOSErrorWithInit):

+ class HierarchyTest(unittest.TestCase): @@ -74,11 +91,6 @@ class HierarchyTest(unittest.TestCase): e = OSError(errcode, "Some message") self.assertIs(type(e), OSError)

- def test_try_except(self): filename = "some_hopefully_non_existing_file" @@ -144,6 +156,44 @@ class AttributesTest(unittest.TestCase): # XXX VMSError not tested +class ExplicitSubclassingTest(unittest.TestCase): +

+

+

+

+

+

+ + def test_main(): support.run_unittest(name)

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ What's New in Python 3.3 Alpha 1? Core and Builtins ----------------- +- Fix OSError.init and OSError.new so that each of them can be

--- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -58,7 +58,7 @@ BaseException_init(PyBaseExceptionObject if (!_PyArg_NoKeywords(Py_TYPE(self)->tp_name, kwds)) return -1;

-static PyObject * -OSError_new(PyTypeObject *type, PyObject *args, PyObject kwds) +/ This function doesn't cleanup on error, the caller should */ +static int +oserror_parse_args(PyObject **p_args,

+#ifdef MS_WINDOWS

+#endif

{

-#ifdef MS_WINDOWS

-#endif -

#ifdef MS_WINDOWS if (nargs >= 2 && nargs <= 4) { if (!PyArg_UnpackTuple(args, "OSError", 2, 4,

@@ -626,59 +623,55 @@ OSError_new(PyTypeObject *type, PyObject errcode = winerror_to_errno(winerrcode); else errcode = winerrcode;

#else if (nargs >= 2 && nargs <= 3) { if (!PyArg_UnpackTuple(args, "OSError", 2, 3,

#endif

+

+}

-

+static int +oserror_init(PyOSErrorObject *self, PyObject **p_args,

+#ifdef MS_WINDOWS

+#endif

+{

/* self->filename will remain Py_None otherwise */ if (filename && filename != Py_None) {

@@ -687,20 +680,15 @@ OSError_new(PyTypeObject type, PyObject if (nargs >= 2 && nargs <= 3) { / filename is removed from the args tuple (for compatibility purposes, see test_exceptions.py) */

Py_DECREF(args); /* replacing args */

- Py_XINCREF(myerrno); self->myerrno = myerrno; @@ -712,6 +700,90 @@ OSError_new(PyTypeObject *type, PyObject self->winerror = winerror; #endif

+

+} + +static PyObject * +OSError_new(PyTypeObject *type, PyObject *args, PyObject *kwds); +static int +OSError_init(PyOSErrorObject *self, PyObject *args, PyObject *kwds); + +static int +oserror_use_init(PyTypeObject *type) +{

+

+

+} + +static PyObject * +OSError_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{

+#ifdef MS_WINDOWS

+#endif +

+

+#ifdef MS_WINDOWS

+#endif

+

+

+

+

+#ifdef MS_WINDOWS

+#endif

+ return (PyObject *) self; error: @@ -721,10 +793,40 @@ error: } static int -OSError_init(PySyntaxErrorObject *self, PyObject *args, PyObject *kwds) +OSError_init(PyOSErrorObject *self, PyObject *args, PyObject *kwds) {

+#ifdef MS_WINDOWS

+#endif +

+

+

+#ifdef MS_WINDOWS

+#endif

+

+#ifdef MS_WINDOWS

+#endif

+ return 0; + +error:

} static int