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
619555d7
Commit
619555d7
authored
Dec 19, 2016
by
Martin Panter
Browse files
Options
Browse Files
Download
Plain Diff
Issue #25677: Merge SyntaxError caret positioning from 3.5
parents
879199ba
ca3263c5
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
5 deletions
+39
-5
Lib/test/test_cmd_line_script.py
Lib/test/test_cmd_line_script.py
+33
-0
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+3
-0
Python/errors.c
Python/errors.c
+1
-4
Python/pythonrun.c
Python/pythonrun.c
+1
-1
No files found.
Lib/test/test_cmd_line_script.py
View file @
619555d7
...
...
@@ -10,6 +10,7 @@ import os
import
os.path
import
py_compile
import
subprocess
import
io
import
textwrap
from
test
import
support
...
...
@@ -539,6 +540,38 @@ class CmdLineTest(unittest.TestCase):
text
=
stderr
.
decode
(
'ascii'
)
self
.
assertEqual
(
text
,
"some text"
)
def
test_syntaxerror_unindented_caret_position
(
self
):
script
=
"1 + 1 = 2
\
n
"
with
support
.
temp_dir
()
as
script_dir
:
script_name
=
_make_test_script
(
script_dir
,
'script'
,
script
)
exitcode
,
stdout
,
stderr
=
assert_python_failure
(
script_name
)
text
=
io
.
TextIOWrapper
(
io
.
BytesIO
(
stderr
),
'ascii'
).
read
()
# Confirm that the caret is located under the first 1 character
self
.
assertIn
(
"
\
n
1 + 1 = 2
\
n
^"
,
text
)
def
test_syntaxerror_indented_caret_position
(
self
):
script
=
textwrap
.
dedent
(
"""
\
if True:
1 + 1 = 2
"""
)
with
support
.
temp_dir
()
as
script_dir
:
script_name
=
_make_test_script
(
script_dir
,
'script'
,
script
)
exitcode
,
stdout
,
stderr
=
assert_python_failure
(
script_name
)
text
=
io
.
TextIOWrapper
(
io
.
BytesIO
(
stderr
),
'ascii'
).
read
()
# Confirm that the caret is located under the first 1 character
self
.
assertIn
(
"
\
n
1 + 1 = 2
\
n
^"
,
text
)
# Try the same with a form feed at the start of the indented line
script
=
(
"if True:
\
n
"
"
\
f
1 + 1 = 2
\
n
"
)
script_name
=
_make_test_script
(
script_dir
,
"script"
,
script
)
exitcode
,
stdout
,
stderr
=
assert_python_failure
(
script_name
)
text
=
io
.
TextIOWrapper
(
io
.
BytesIO
(
stderr
),
"ascii"
).
read
()
self
.
assertNotIn
(
"
\
f
"
,
text
)
self
.
assertIn
(
"
\
n
1 + 1 = 2
\
n
^"
,
text
)
def
test_main
():
support
.
run_unittest
(
CmdLineTest
)
...
...
Misc/ACKS
View file @
619555d7
...
...
@@ -851,6 +851,7 @@ Julia Lawall
Chris Lawrence
Mark Lawrence
Chris Laws
Michael Layzell
Michael Lazar
Brian Leair
Mathieu Leduc-Hamel
...
...
Misc/NEWS
View file @
619555d7
...
...
@@ -10,6 +10,9 @@ What's New in Python 3.6.1 release candidate 1
Core and Builtins
-----------------
- Issue #25677: Correct the positioning of the syntax error caret for
indented blocks. Based on patch by Michael Layzell.
- Issue #29000: Fixed bytes formatting of octals with zero padding in alternate
form.
...
...
Python/errors.c
View file @
619555d7
...
...
@@ -1144,11 +1144,8 @@ err_programtext(FILE *fp, int lineno)
}
fclose
(
fp
);
if
(
i
==
lineno
)
{
char
*
p
=
linebuf
;
PyObject
*
res
;
while
(
*
p
==
' '
||
*
p
==
'\t'
||
*
p
==
'\014'
)
p
++
;
res
=
PyUnicode_FromString
(
p
);
res
=
PyUnicode_FromString
(
linebuf
);
if
(
res
==
NULL
)
PyErr_Clear
();
return
res
;
...
...
Python/pythonrun.c
View file @
619555d7
...
...
@@ -528,7 +528,7 @@ print_error_text(PyObject *f, int offset, PyObject *text_obj)
offset
-=
(
int
)(
nl
+
1
-
text
);
text
=
nl
+
1
;
}
while
(
*
text
==
' '
||
*
text
==
'\t'
)
{
while
(
*
text
==
' '
||
*
text
==
'\t'
||
*
text
==
'\f'
)
{
text
++
;
offset
--
;
}
...
...
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