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
f2269261
Commit
f2269261
authored
Jan 22, 2014
by
Florent Xicluna
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #17825: Cursor ^ is correctly positioned for SyntaxError and IndentationError.
parent
679357e8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
3 deletions
+17
-3
Lib/test/test_traceback.py
Lib/test/test_traceback.py
+10
-0
Lib/traceback.py
Lib/traceback.py
+4
-3
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/test/test_traceback.py
View file @
f2269261
...
...
@@ -35,6 +35,9 @@ class TracebackCases(unittest.TestCase):
def
syntax_error_bad_indentation
(
self
):
compile
(
"def spam():
\
n
print 1
\
n
print 2"
,
"?"
,
"exec"
)
def
syntax_error_bad_indentation2
(
self
):
compile
(
" print(2)"
,
"?"
,
"exec"
)
def
test_caret
(
self
):
err
=
self
.
get_exception_format
(
self
.
syntax_error_with_caret
,
SyntaxError
)
...
...
@@ -111,6 +114,13 @@ def test():
os
.
unlink
(
os
.
path
.
join
(
testdir
,
f
))
os
.
rmdir
(
testdir
)
err
=
self
.
get_exception_format
(
self
.
syntax_error_bad_indentation2
,
IndentationError
)
self
.
assertEqual
(
len
(
err
),
4
)
self
.
assertEqual
(
err
[
1
].
strip
(),
"print(2)"
)
self
.
assertIn
(
"^"
,
err
[
2
])
self
.
assertEqual
(
err
[
1
].
find
(
"p"
),
err
[
2
].
find
(
"^"
))
def
test_base_exception
(
self
):
# Test that exceptions derived from BaseException are formatted right
e
=
KeyboardInterrupt
()
...
...
Lib/traceback.py
View file @
f2269261
...
...
@@ -189,11 +189,12 @@ def format_exception_only(etype, value):
if
badline
is
not
None
:
lines
.
append
(
' %s
\
n
'
%
badline
.
strip
())
if
offset
is
not
None
:
caretspace
=
badline
.
rstrip
(
'
\
n
'
)[:
offset
].
lstrip
()
caretspace
=
badline
.
rstrip
(
'
\
n
'
)
offset
=
min
(
len
(
caretspace
),
offset
)
-
1
caretspace
=
caretspace
[:
offset
].
lstrip
()
# non-space whitespace (likes tabs) must be kept for alignment
caretspace
=
((
c
.
isspace
()
and
c
or
' '
)
for
c
in
caretspace
)
# only three spaces to account for offset1 == pos 0
lines
.
append
(
' %s^
\
n
'
%
''
.
join
(
caretspace
))
lines
.
append
(
' %s^
\
n
'
%
''
.
join
(
caretspace
))
value
=
msg
lines
.
append
(
_format_final_exc_line
(
stype
,
value
))
...
...
Misc/NEWS
View file @
f2269261
...
...
@@ -9,6 +9,9 @@ What's New in Python 2.7.7?
Core and Builtins
-----------------
- Issue #17825: Cursor "^" is correctly positioned for SyntaxError and
IndentationError.
- Issue #19081: When a zipimport .zip file in sys.path being imported from
is modified during the lifetime of the Python process after zipimport has
already cached the zip'
s
table
of
contents
we
detect
this
and
recover
...
...
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