Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2633c69

Browse files
committed
Remove the exceptions builtin module, all the exceptions are already builtin.
1 parent f543348 commit 2633c69

15 files changed

Lines changed: 34 additions & 66 deletions

File tree

Lib/ctypes/test/test_structures.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,20 +294,20 @@ class Person(Structure):
294294
# In Python 2.5, Exception is a new-style class, and the repr changed
295295
if issubclass(Exception, object):
296296
self.failUnlessEqual(msg,
297-
"(Phone) <type 'exceptions.TypeError'>: "
297+
"(Phone) <type 'TypeError'>: "
298298
"expected string or Unicode object, int found")
299299
else:
300300
self.failUnlessEqual(msg,
301-
"(Phone) exceptions.TypeError: "
301+
"(Phone) TypeError: "
302302
"expected string or Unicode object, int found")
303303

304304
cls, msg = self.get_except(Person, "Someone", ("a", "b", "c"))
305305
self.failUnlessEqual(cls, RuntimeError)
306306
if issubclass(Exception, object):
307307
self.failUnlessEqual(msg,
308-
"(Phone) <type 'exceptions.ValueError'>: too many initializers")
308+
"(Phone) <type 'ValueError'>: too many initializers")
309309
else:
310-
self.failUnlessEqual(msg, "(Phone) exceptions.ValueError: too many initializers")
310+
self.failUnlessEqual(msg, "(Phone) ValueError: too many initializers")
311311

312312

313313
def get_except(self, func, *args):

Lib/test/output/test_logging

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -488,12 +488,12 @@ INFO:a.b.c.d:Info 5
488488
-- log_test4 begin ---------------------------------------------------
489489
config0: ok.
490490
config1: ok.
491-
config2: <type 'exceptions.AttributeError'>
492-
config3: <type 'exceptions.KeyError'>
491+
config2: <type 'AttributeError'>
492+
config3: <type 'KeyError'>
493493
-- log_test4 end ---------------------------------------------------
494494
-- log_test5 begin ---------------------------------------------------
495495
ERROR:root:just testing
496-
<type 'exceptions.KeyError'>... Don't panic!
496+
<type 'KeyError'>... Don't panic!
497497
-- log_test5 end ---------------------------------------------------
498498
-- logrecv output begin ---------------------------------------------------
499499
ERR -> CRITICAL: Message 0 (via logrecv.tcp.ERR)

Lib/test/test_exceptions.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,6 @@
1515

1616
class ExceptionTests(unittest.TestCase):
1717

18-
def testReload(self):
19-
# Reloading the built-in exceptions module failed prior to Py2.2, while it
20-
# should act the same as reloading built-in sys.
21-
try:
22-
import exceptions
23-
reload(exceptions)
24-
except ImportError as e:
25-
self.fail("reloading exceptions: %s" % e)
26-
2718
def raise_catch(self, exc, excname):
2819
try:
2920
raise exc, "spam"
@@ -289,7 +280,7 @@ def testAttributes(self):
289280
if type(e) is not exc:
290281
raise
291282
# Verify module name
292-
self.assertEquals(type(e).__module__, 'exceptions')
283+
self.assertEquals(type(e).__module__, '__builtin__')
293284
# Verify no ref leaks in Exc_str()
294285
s = str(e)
295286
for checkArgName in expected:

Lib/test/test_generators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,7 +1691,7 @@ def printsolution(self, x):
16911691
>>> g.next()
16921692
>>> del g
16931693
>>> sys.stderr.getvalue().startswith(
1694-
... "Exception exceptions.RuntimeError: 'generator ignored GeneratorExit' in "
1694+
... "Exception RuntimeError: 'generator ignored GeneratorExit' in "
16951695
... )
16961696
True
16971697
>>> sys.stderr = old
@@ -1808,7 +1808,7 @@ def printsolution(self, x):
18081808
... del l
18091809
... err = sys.stderr.getvalue().strip()
18101810
... err.startswith(
1811-
... "Exception exceptions.RuntimeError: RuntimeError() in <"
1811+
... "Exception RuntimeError: RuntimeError() in <"
18121812
... )
18131813
... err.endswith("> ignored")
18141814
... len(err.splitlines())

Lib/test/test_modulefinder.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"a.module",
8888
["a", "a.module",
8989
"b", "b.x", "b.y", "b.z",
90-
"__future__", "sys", "exceptions"],
90+
"__future__", "sys", "gc"],
9191
["blahblah", "z"], [],
9292
"""\
9393
mymodule.py
@@ -96,11 +96,11 @@
9696
from __future__ import absolute_import
9797
import sys # sys
9898
import blahblah # fails
99-
import exceptions # exceptions
99+
import gc # gc
100100
import b.x # b.x
101101
from b import y # b.y
102102
from b.z import * # b.z.*
103-
a/exceptions.py
103+
a/gc.py
104104
a/sys.py
105105
import mymodule
106106
a/b/__init__.py
@@ -123,16 +123,16 @@
123123
"a.b.c", "a.b.c.moduleC",
124124
"a.b.c.d", "a.b.c.e",
125125
"a.b.x",
126-
"exceptions"],
126+
"gc"],
127127
[], [],
128128
"""\
129129
mymodule.py
130130
a/__init__.py
131131
from .b import y, z # a.b.y, a.b.z
132132
a/module.py
133133
from __future__ import absolute_import # __future__
134-
import exceptions # exceptions
135-
a/exceptions.py
134+
import gc # gc
135+
a/gc.py
136136
a/sys.py
137137
a/b/__init__.py
138138
from ..b import x # a.b.x
@@ -170,7 +170,7 @@
170170
a/another.py
171171
a/module.py
172172
from .b import y, z # a.b.y, a.b.z
173-
a/exceptions.py
173+
a/gc.py
174174
a/sys.py
175175
a/b/__init__.py
176176
from .c import moduleC # a.b.c.moduleC

Lib/test/test_weakref.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ def test_proxy_ref(self):
104104
def check(proxy):
105105
proxy.bar
106106

107-
self.assertRaises(weakref.ReferenceError, check, ref1)
108-
self.assertRaises(weakref.ReferenceError, check, ref2)
109-
self.assertRaises(weakref.ReferenceError, bool, weakref.proxy(C()))
107+
self.assertRaises(ReferenceError, check, ref1)
108+
self.assertRaises(ReferenceError, check, ref2)
109+
self.assertRaises(ReferenceError, bool, weakref.proxy(C()))
110110
self.assert_(self.cbcalled == 2)
111111

112112
def check_basic_ref(self, factory):

Lib/traceback.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def format_exception_only(etype, value):
169169

170170
stype = etype.__name__
171171
smod = etype.__module__
172-
if smod not in ("exceptions", "__main__", "__builtin__"):
172+
if smod not in ("__main__", "__builtin__"):
173173
stype = smod + '.' + stype
174174

175175
if not issubclass(etype, SyntaxError):

Lib/weakref.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
ProxyType,
2121
ReferenceType)
2222

23-
from exceptions import ReferenceError
24-
2523

2624
ProxyTypes = (ProxyType, CallableProxyType)
2725

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ TO DO
2828
Core and Builtins
2929
-----------------
3030

31+
- Remove the exceptions module, all the exceptions are already builtin.
32+
3133
- input() becomes raw_input(): the name input() now implements the
3234
functionality formerly known as raw_input(); the name raw_input()
3335
is no longer defined.

Objects/exceptions.c

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,11 @@
1010
#include "osdefs.h"
1111

1212
#define MAKE_IT_NONE(x) (x) = Py_None; Py_INCREF(Py_None);
13-
#define EXC_MODULE_NAME "exceptions."
1413

1514
/* NOTE: If the exception class hierarchy changes, don't forget to update
1615
* Lib/test/exception_hierarchy.txt
1716
*/
1817

19-
PyDoc_STRVAR(exceptions_doc, "Python's standard exception class hierarchy.\n\
20-
\n\
21-
Exceptions found here are defined both in the exceptions module and the\n\
22-
built-in namespace. It is recommended that user-defined exceptions\n\
23-
inherit from Exception. See the documentation for the exception\n\
24-
inheritance hierarchy.\n\
25-
");
26-
2718
/*
2819
* BaseException
2920
*/
@@ -282,7 +273,7 @@ static PyGetSetDef BaseException_getset[] = {
282273
static PyTypeObject _PyExc_BaseException = {
283274
PyObject_HEAD_INIT(NULL)
284275
0, /*ob_size*/
285-
EXC_MODULE_NAME "BaseException", /*tp_name*/
276+
"BaseException", /*tp_name*/
286277
sizeof(PyBaseExceptionObject), /*tp_basicsize*/
287278
0, /*tp_itemsize*/
288279
(destructor)BaseException_dealloc, /*tp_dealloc*/
@@ -333,7 +324,7 @@ PyObject *PyExc_BaseException = (PyObject *)&_PyExc_BaseException;
333324
static PyTypeObject _PyExc_ ## EXCNAME = { \
334325
PyObject_HEAD_INIT(NULL) \
335326
0, \
336-
EXC_MODULE_NAME # EXCNAME, \
327+
# EXCNAME, \
337328
sizeof(PyBaseExceptionObject), \
338329
0, (destructor)BaseException_dealloc, 0, 0, 0, 0, 0, 0, 0, \
339330
0, 0, 0, 0, 0, 0, 0, \
@@ -349,7 +340,7 @@ PyObject *PyExc_ ## EXCNAME = (PyObject *)&_PyExc_ ## EXCNAME
349340
static PyTypeObject _PyExc_ ## EXCNAME = { \
350341
PyObject_HEAD_INIT(NULL) \
351342
0, \
352-
EXC_MODULE_NAME # EXCNAME, \
343+
# EXCNAME, \
353344
sizeof(Py ## EXCSTORE ## Object), \
354345
0, (destructor)EXCSTORE ## _dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
355346
0, 0, 0, 0, 0, \
@@ -365,7 +356,7 @@ PyObject *PyExc_ ## EXCNAME = (PyObject *)&_PyExc_ ## EXCNAME
365356
static PyTypeObject _PyExc_ ## EXCNAME = { \
366357
PyObject_HEAD_INIT(NULL) \
367358
0, \
368-
EXC_MODULE_NAME # EXCNAME, \
359+
# EXCNAME, \
369360
sizeof(Py ## EXCSTORE ## Object), 0, \
370361
(destructor)EXCSTORE ## _dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
371362
(reprfunc)EXCSTR, 0, 0, 0, \
@@ -1632,7 +1623,7 @@ UnicodeEncodeError_str(PyObject *self)
16321623
static PyTypeObject _PyExc_UnicodeEncodeError = {
16331624
PyObject_HEAD_INIT(NULL)
16341625
0,
1635-
EXC_MODULE_NAME "UnicodeEncodeError",
1626+
"UnicodeEncodeError",
16361627
sizeof(PyUnicodeErrorObject), 0,
16371628
(destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
16381629
(reprfunc)UnicodeEncodeError_str, 0, 0, 0,
@@ -1704,7 +1695,7 @@ UnicodeDecodeError_str(PyObject *self)
17041695
static PyTypeObject _PyExc_UnicodeDecodeError = {
17051696
PyObject_HEAD_INIT(NULL)
17061697
0,
1707-
EXC_MODULE_NAME "UnicodeDecodeError",
1698+
"UnicodeDecodeError",
17081699
sizeof(PyUnicodeErrorObject), 0,
17091700
(destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
17101701
(reprfunc)UnicodeDecodeError_str, 0, 0, 0,
@@ -1802,7 +1793,7 @@ UnicodeTranslateError_str(PyObject *self)
18021793
static PyTypeObject _PyExc_UnicodeTranslateError = {
18031794
PyObject_HEAD_INIT(NULL)
18041795
0,
1805-
EXC_MODULE_NAME "UnicodeTranslateError",
1796+
"UnicodeTranslateError",
18061797
sizeof(PyUnicodeErrorObject), 0,
18071798
(destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
18081799
(reprfunc)UnicodeTranslateError_str, 0, 0, 0,
@@ -1956,17 +1947,10 @@ SimpleExtendsException(PyExc_Warning, UnicodeWarning,
19561947
*/
19571948
PyObject *PyExc_MemoryErrorInst=NULL;
19581949

1959-
/* module global functions */
1960-
static PyMethodDef functions[] = {
1961-
/* Sentinel */
1962-
{NULL, NULL}
1963-
};
1964-
19651950
#define PRE_INIT(TYPE) if (PyType_Ready(&_PyExc_ ## TYPE) < 0) \
19661951
Py_FatalError("exceptions bootstrapping error.");
19671952

19681953
#define POST_INIT(TYPE) Py_INCREF(PyExc_ ## TYPE); \
1969-
PyModule_AddObject(m, # TYPE, PyExc_ ## TYPE); \
19701954
if (PyDict_SetItemString(bdict, # TYPE, PyExc_ ## TYPE)) \
19711955
Py_FatalError("Module dictionary insertion problem.");
19721956

@@ -1996,7 +1980,7 @@ InvalidParameterHandler(
19961980
PyMODINIT_FUNC
19971981
_PyExc_Init(void)
19981982
{
1999-
PyObject *m, *bltinmod, *bdict;
1983+
PyObject *bltinmod, *bdict;
20001984

20011985
PRE_INIT(BaseException)
20021986
PRE_INIT(Exception)
@@ -2053,10 +2037,6 @@ _PyExc_Init(void)
20532037
PRE_INIT(ImportWarning)
20542038
PRE_INIT(UnicodeWarning)
20552039

2056-
m = Py_InitModule4("exceptions", functions, exceptions_doc,
2057-
(PyObject *)NULL, PYTHON_API_VERSION);
2058-
if (m == NULL) return;
2059-
20602040
bltinmod = PyImport_ImportModule("__builtin__");
20612041
if (bltinmod == NULL)
20622042
Py_FatalError("exceptions bootstrapping error.");

0 commit comments

Comments
 (0)