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
c70e003f
Commit
c70e003f
authored
Sep 21, 2006
by
Brett Cannon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backport of fix to allow exception instances to be sliced once again.
parent
7dcdeaf1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
1 deletion
+26
-1
Lib/test/test_exceptions.py
Lib/test/test_exceptions.py
+7
-0
Misc/NEWS
Misc/NEWS
+11
-0
Objects/exceptions.c
Objects/exceptions.c
+8
-1
No files found.
Lib/test/test_exceptions.py
View file @
c70e003f
...
...
@@ -279,6 +279,13 @@ class ExceptionTests(unittest.TestCase):
'pickled "%r", attribute "%s'
%
(
e
,
checkArgName
))
def
testSlicing
(
self
):
# Test that you can slice an exception directly instead of requiring
# going through the 'args' attribute.
args
=
(
1
,
2
,
3
)
exc
=
BaseException
(
*
args
)
self
.
failUnlessEqual
(
exc
[:],
args
)
def
testKeywordArgs
(
self
):
# test that builtin exception don't take keyword args,
# but user-defined subclasses can if they want
...
...
Misc/NEWS
View file @
c70e003f
...
...
@@ -4,6 +4,17 @@ Python News
(
editors
:
check
NEWS
.
help
for
information
about
editing
NEWS
using
ReST
.)
What
's New in Python 2.5.1c1?
=============================
*Release date: XX-XXX-XXXX*
Core and builtins
-----------------
- Allow exception instances to be directly sliced again.
What'
s
New
in
Python
2.5
(
final
)
================================
...
...
Objects/exceptions.c
View file @
c70e003f
...
...
@@ -190,12 +190,19 @@ BaseException_getitem(PyBaseExceptionObject *self, Py_ssize_t index)
return
PySequence_GetItem
(
self
->
args
,
index
);
}
static
PyObject
*
BaseException_getslice
(
PyBaseExceptionObject
*
self
,
Py_ssize_t
start
,
Py_ssize_t
stop
)
{
return
PySequence_GetSlice
(
self
->
args
,
start
,
stop
);
}
static
PySequenceMethods
BaseException_as_sequence
=
{
0
,
/* sq_length; */
0
,
/* sq_concat; */
0
,
/* sq_repeat; */
(
ssizeargfunc
)
BaseException_getitem
,
/* sq_item; */
0
,
/* sq_slice; */
(
ssizessizeargfunc
)
BaseException_getslice
,
/* sq_slice; */
0
,
/* sq_ass_item; */
0
,
/* sq_ass_slice; */
0
,
/* sq_contains; */
...
...
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