Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
4842ba1e
Commit
4842ba1e
authored
Sep 09, 2006
by
Brett Cannon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove __unicode__ method so that ``unicode(BaseException)`` succeeds.
Fixes bug #1551432.
parent
4df138ab
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
19 deletions
+13
-19
Lib/test/test_exceptions.py
Lib/test/test_exceptions.py
+9
-0
Lib/test/test_pep352.py
Lib/test/test_pep352.py
+1
-2
Misc/NEWS
Misc/NEWS
+3
-0
Objects/exceptions.c
Objects/exceptions.c
+0
-17
No files found.
Lib/test/test_exceptions.py
View file @
4842ba1e
...
...
@@ -304,6 +304,15 @@ class ExceptionTests(unittest.TestCase):
return
-
1
self
.
assertRaises
(
RuntimeError
,
g
)
def
testUnicodeStrUsage
(
self
):
# Make sure both instances and classes have a str and unicode
# representation.
self
.
failUnless
(
str
(
Exception
))
self
.
failUnless
(
unicode
(
Exception
))
self
.
failUnless
(
str
(
Exception
(
'a'
)))
self
.
failUnless
(
unicode
(
Exception
(
u'a'
)))
def
test_main
():
run_unittest
(
ExceptionTests
)
...
...
Lib/test/test_pep352.py
View file @
4842ba1e
...
...
@@ -15,8 +15,7 @@ class ExceptionClassTests(unittest.TestCase):
self
.
failUnless
(
issubclass
(
Exception
,
object
))
def
verify_instance_interface
(
self
,
ins
):
for
attr
in
(
"args"
,
"message"
,
"__str__"
,
"__unicode__"
,
"__repr__"
,
"__getitem__"
):
for
attr
in
(
"args"
,
"message"
,
"__str__"
,
"__repr__"
,
"__getitem__"
):
self
.
failUnless
(
hasattr
(
ins
,
attr
),
"%s missing %s attribute"
%
(
ins
.
__class__
.
__name__
,
attr
))
...
...
Misc/NEWS
View file @
4842ba1e
...
...
@@ -19,6 +19,9 @@ What's New in Python 2.5 release candidate 2?
Core
and
builtins
-----------------
-
Bug
#
1551432
:
Exceptions
do
not
define
an
explicit
__unicode__
method
.
This
allows
calling
unicode
()
on
exceptions
classes
directly
to
succeed
.
-
Bug
#
1542051
:
Exceptions
now
correctly
call
PyObject_GC_UnTrack
.
Also
make
sure
that
every
exception
class
has
__module__
set
to
'exceptions'
.
...
...
Objects/exceptions.c
View file @
4842ba1e
...
...
@@ -175,27 +175,10 @@ BaseException_setstate(PyObject *self, PyObject *state)
Py_RETURN_NONE
;
}
#ifdef Py_USING_UNICODE
/* while this method generates fairly uninspired output, it a least
* guarantees that we can display exceptions that have unicode attributes
*/
static
PyObject
*
BaseException_unicode
(
PyBaseExceptionObject
*
self
)
{
if
(
PyTuple_GET_SIZE
(
self
->
args
)
==
0
)
return
PyUnicode_FromUnicode
(
NULL
,
0
);
if
(
PyTuple_GET_SIZE
(
self
->
args
)
==
1
)
return
PyObject_Unicode
(
PyTuple_GET_ITEM
(
self
->
args
,
0
));
return
PyObject_Unicode
(
self
->
args
);
}
#endif
/* Py_USING_UNICODE */
static
PyMethodDef
BaseException_methods
[]
=
{
{
"__reduce__"
,
(
PyCFunction
)
BaseException_reduce
,
METH_NOARGS
},
{
"__setstate__"
,
(
PyCFunction
)
BaseException_setstate
,
METH_O
},
#ifdef Py_USING_UNICODE
{
"__unicode__"
,
(
PyCFunction
)
BaseException_unicode
,
METH_NOARGS
},
#endif
{
NULL
,
NULL
,
0
,
NULL
},
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment