# In Python 2.5, Exception is a new-style class, and the repr changed
if issubclass(Exception, object):
self.failUnlessEqual(msg,
- "(Phone) <type 'exceptions.TypeError'>: "
+ "(Phone) <type 'TypeError'>: "
"expected string or Unicode object, int found")
else:
self.failUnlessEqual(msg,
- "(Phone) exceptions.TypeError: "
+ "(Phone) TypeError: "
"expected string or Unicode object, int found")
cls, msg = self.get_except(Person, "Someone", ("a", "b", "c"))
self.failUnlessEqual(cls, RuntimeError)
if issubclass(Exception, object):
self.failUnlessEqual(msg,
- "(Phone) <type 'exceptions.ValueError'>: too many initializers")
+ "(Phone) <type 'ValueError'>: too many initializers")
else:
- self.failUnlessEqual(msg, "(Phone) exceptions.ValueError: too many initializers")
+ self.failUnlessEqual(msg, "(Phone) ValueError: too many initializers")
def get_except(self, func, *args):
-- log_test4 begin ---------------------------------------------------
config0: ok.
config1: ok.
-config2: <type 'exceptions.AttributeError'>
-config3: <type 'exceptions.KeyError'>
+config2: <type 'AttributeError'>
+config3: <type 'KeyError'>
-- log_test4 end ---------------------------------------------------
-- log_test5 begin ---------------------------------------------------
ERROR:root:just testing
-<type 'exceptions.KeyError'>... Don't panic!
+<type 'KeyError'>... Don't panic!
-- log_test5 end ---------------------------------------------------
-- logrecv output begin ---------------------------------------------------
ERR -> CRITICAL: Message 0 (via logrecv.tcp.ERR)
class ExceptionTests(unittest.TestCase):
- def testReload(self):
- # Reloading the built-in exceptions module failed prior to Py2.2, while it
- # should act the same as reloading built-in sys.
- try:
- import exceptions
- reload(exceptions)
- except ImportError as e:
- self.fail("reloading exceptions: %s" % e)
-
def raise_catch(self, exc, excname):
try:
raise exc, "spam"
if type(e) is not exc:
raise
# Verify module name
- self.assertEquals(type(e).__module__, 'exceptions')
+ self.assertEquals(type(e).__module__, '__builtin__')
# Verify no ref leaks in Exc_str()
s = str(e)
for checkArgName in expected:
>>> g.next()
>>> del g
>>> sys.stderr.getvalue().startswith(
-... "Exception exceptions.RuntimeError: 'generator ignored GeneratorExit' in "
+... "Exception RuntimeError: 'generator ignored GeneratorExit' in "
... )
True
>>> sys.stderr = old
... del l
... err = sys.stderr.getvalue().strip()
... err.startswith(
-... "Exception exceptions.RuntimeError: RuntimeError() in <"
+... "Exception RuntimeError: RuntimeError() in <"
... )
... err.endswith("> ignored")
... len(err.splitlines())
"a.module",
["a", "a.module",
"b", "b.x", "b.y", "b.z",
- "__future__", "sys", "exceptions"],
+ "__future__", "sys", "gc"],
["blahblah", "z"], [],
"""\
mymodule.py
from __future__ import absolute_import
import sys # sys
import blahblah # fails
- import exceptions # exceptions
+ import gc # gc
import b.x # b.x
from b import y # b.y
from b.z import * # b.z.*
-a/exceptions.py
+a/gc.py
a/sys.py
import mymodule
a/b/__init__.py
"a.b.c", "a.b.c.moduleC",
"a.b.c.d", "a.b.c.e",
"a.b.x",
- "exceptions"],
+ "gc"],
[], [],
"""\
mymodule.py
from .b import y, z # a.b.y, a.b.z
a/module.py
from __future__ import absolute_import # __future__
- import exceptions # exceptions
-a/exceptions.py
+ import gc # gc
+a/gc.py
a/sys.py
a/b/__init__.py
from ..b import x # a.b.x
a/another.py
a/module.py
from .b import y, z # a.b.y, a.b.z
-a/exceptions.py
+a/gc.py
a/sys.py
a/b/__init__.py
from .c import moduleC # a.b.c.moduleC
def check(proxy):
proxy.bar
- self.assertRaises(weakref.ReferenceError, check, ref1)
- self.assertRaises(weakref.ReferenceError, check, ref2)
- self.assertRaises(weakref.ReferenceError, bool, weakref.proxy(C()))
+ self.assertRaises(ReferenceError, check, ref1)
+ self.assertRaises(ReferenceError, check, ref2)
+ self.assertRaises(ReferenceError, bool, weakref.proxy(C()))
self.assert_(self.cbcalled == 2)
def check_basic_ref(self, factory):
stype = etype.__name__
smod = etype.__module__
- if smod not in ("exceptions", "__main__", "__builtin__"):
+ if smod not in ("__main__", "__builtin__"):
stype = smod + '.' + stype
if not issubclass(etype, SyntaxError):
ProxyType,
ReferenceType)
-from exceptions import ReferenceError
-
ProxyTypes = (ProxyType, CallableProxyType)
Core and Builtins
-----------------
+- Remove the exceptions module, all the exceptions are already builtin.
+
- input() becomes raw_input(): the name input() now implements the
functionality formerly known as raw_input(); the name raw_input()
is no longer defined.
#include "osdefs.h"
#define MAKE_IT_NONE(x) (x) = Py_None; Py_INCREF(Py_None);
-#define EXC_MODULE_NAME "exceptions."
/* NOTE: If the exception class hierarchy changes, don't forget to update
* Lib/test/exception_hierarchy.txt
*/
-PyDoc_STRVAR(exceptions_doc, "Python's standard exception class hierarchy.\n\
-\n\
-Exceptions found here are defined both in the exceptions module and the\n\
-built-in namespace. It is recommended that user-defined exceptions\n\
-inherit from Exception. See the documentation for the exception\n\
-inheritance hierarchy.\n\
-");
-
/*
* BaseException
*/
static PyTypeObject _PyExc_BaseException = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
- EXC_MODULE_NAME "BaseException", /*tp_name*/
+ "BaseException", /*tp_name*/
sizeof(PyBaseExceptionObject), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor)BaseException_dealloc, /*tp_dealloc*/
static PyTypeObject _PyExc_ ## EXCNAME = { \
PyObject_HEAD_INIT(NULL) \
0, \
- EXC_MODULE_NAME # EXCNAME, \
+ # EXCNAME, \
sizeof(PyBaseExceptionObject), \
0, (destructor)BaseException_dealloc, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, \
static PyTypeObject _PyExc_ ## EXCNAME = { \
PyObject_HEAD_INIT(NULL) \
0, \
- EXC_MODULE_NAME # EXCNAME, \
+ # EXCNAME, \
sizeof(Py ## EXCSTORE ## Object), \
0, (destructor)EXCSTORE ## _dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, \
static PyTypeObject _PyExc_ ## EXCNAME = { \
PyObject_HEAD_INIT(NULL) \
0, \
- EXC_MODULE_NAME # EXCNAME, \
+ # EXCNAME, \
sizeof(Py ## EXCSTORE ## Object), 0, \
(destructor)EXCSTORE ## _dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
(reprfunc)EXCSTR, 0, 0, 0, \
static PyTypeObject _PyExc_UnicodeEncodeError = {
PyObject_HEAD_INIT(NULL)
0,
- EXC_MODULE_NAME "UnicodeEncodeError",
+ "UnicodeEncodeError",
sizeof(PyUnicodeErrorObject), 0,
(destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
(reprfunc)UnicodeEncodeError_str, 0, 0, 0,
static PyTypeObject _PyExc_UnicodeDecodeError = {
PyObject_HEAD_INIT(NULL)
0,
- EXC_MODULE_NAME "UnicodeDecodeError",
+ "UnicodeDecodeError",
sizeof(PyUnicodeErrorObject), 0,
(destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
(reprfunc)UnicodeDecodeError_str, 0, 0, 0,
static PyTypeObject _PyExc_UnicodeTranslateError = {
PyObject_HEAD_INIT(NULL)
0,
- EXC_MODULE_NAME "UnicodeTranslateError",
+ "UnicodeTranslateError",
sizeof(PyUnicodeErrorObject), 0,
(destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
(reprfunc)UnicodeTranslateError_str, 0, 0, 0,
*/
PyObject *PyExc_MemoryErrorInst=NULL;
-/* module global functions */
-static PyMethodDef functions[] = {
- /* Sentinel */
- {NULL, NULL}
-};
-
#define PRE_INIT(TYPE) if (PyType_Ready(&_PyExc_ ## TYPE) < 0) \
Py_FatalError("exceptions bootstrapping error.");
#define POST_INIT(TYPE) Py_INCREF(PyExc_ ## TYPE); \
- PyModule_AddObject(m, # TYPE, PyExc_ ## TYPE); \
if (PyDict_SetItemString(bdict, # TYPE, PyExc_ ## TYPE)) \
Py_FatalError("Module dictionary insertion problem.");
PyMODINIT_FUNC
_PyExc_Init(void)
{
- PyObject *m, *bltinmod, *bdict;
+ PyObject *bltinmod, *bdict;
PRE_INIT(BaseException)
PRE_INIT(Exception)
PRE_INIT(ImportWarning)
PRE_INIT(UnicodeWarning)
- m = Py_InitModule4("exceptions", functions, exceptions_doc,
- (PyObject *)NULL, PYTHON_API_VERSION);
- if (m == NULL) return;
-
bltinmod = PyImport_ImportModule("__builtin__");
if (bltinmod == NULL)
Py_FatalError("exceptions bootstrapping error.");
{"__main__", NULL},
{"__builtin__", NULL},
{"sys", NULL},
- {"exceptions", NULL},
{"_types", init_types},
{"__main__", NULL},
{"__builtin__", NULL},
{"sys", NULL},
- {"exceptions", NULL},
/* This lives in gcmodule.c */
{"gc", initgc},
PyFile_WriteString("<unknown>", f);
else {
char* modstr = PyString_AsString(moduleName);
- if (modstr)
+ if (modstr &&
+ strcmp(modstr, "__builtin__") != 0)
{
PyFile_WriteString(modstr, f);
PyFile_WriteString(".", f);
/* initialize builtin exceptions */
_PyExc_Init();
- _PyImport_FixupExtension("exceptions", "exceptions");
/* phase 2 of builtins */
_PyImport_FixupExtension("__builtin__", "__builtin__");
err = PyFile_WriteString("<unknown>", f);
else {
char* modstr = PyString_AsString(moduleName);
- if (modstr && strcmp(modstr, "exceptions"))
+ if (modstr && strcmp(modstr, "__builtin__"))
{
err = PyFile_WriteString(modstr, f);
err += PyFile_WriteString(".", f);
{"__main__", NULL},
{"__builtin__", NULL},
{"sys", NULL},
- {"exceptions", NULL},
/* This lives in gcmodule.c */
{"gc", initgc},