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
94cf308e
Commit
94cf308e
authored
Dec 17, 2018
by
Serhiy Storchaka
Committed by
GitHub
Dec 17, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-33306: Improve SyntaxError messages for unbalanced parentheses. (GH-6516)
parent
bdabb073
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
7 deletions
+47
-7
Lib/test/test_fstring.py
Lib/test/test_fstring.py
+8
-4
Lib/test/test_site.py
Lib/test/test_site.py
+2
-2
Misc/NEWS.d/next/Core and Builtins/2018-04-18-12-23-30.bpo-33306.tSM3cp.rst
...ore and Builtins/2018-04-18-12-23-30.bpo-33306.tSM3cp.rst
+1
-0
Parser/tokenizer.c
Parser/tokenizer.c
+32
-0
Parser/tokenizer.h
Parser/tokenizer.h
+4
-1
No files found.
Lib/test/test_fstring.py
View file @
94cf308e
...
...
@@ -1004,10 +1004,14 @@ non-important content
self.assertEqual('
{
d
[
0
]
}
'.format(d=d), '
integer
')
def test_invalid_expressions(self):
self.assertAllRaise(SyntaxError, '
invalid
syntax
',
[r"f'
{
a
[
4
)
}
'",
r"f'
{
a
(
4
]
}
'",
])
self.assertAllRaise(SyntaxError,
r"closing parenthesis '
\
)
' does not match "
r"opening parenthesis '
\
[
'
\
(<
f
string>, line 1
\
)
"
,
[r"f'
{
a
[
4
)
}
'"])
self.assertAllRaise(SyntaxError,
r"closing parenthesis '
\
]
' does not match "
r"opening parenthesis '
\
(
'
\
(<
f
string>, line 1
\
)
"
,
[r"f'
{
a
(
4
]
}
'"])
def test_errors(self):
# see issue 26287
...
...
Lib/test/test_site.py
View file @
94cf308e
...
...
@@ -133,7 +133,7 @@ class HelperFunctionsTests(unittest.TestCase):
def
test_addpackage_import_bad_syntax
(
self
):
# Issue 10642
pth_dir
,
pth_fn
=
self
.
make_pth
(
"import bad
)
syntax
\
n
"
)
pth_dir
,
pth_fn
=
self
.
make_pth
(
"import bad
-
syntax
\
n
"
)
with
captured_stderr
()
as
err_out
:
site
.
addpackage
(
pth_dir
,
pth_fn
,
set
())
self
.
assertRegex
(
err_out
.
getvalue
(),
"line 1"
)
...
...
@@ -143,7 +143,7 @@ class HelperFunctionsTests(unittest.TestCase):
# order doesn't matter. The next three could be a single check
# but my regex foo isn't good enough to write it.
self
.
assertRegex
(
err_out
.
getvalue
(),
'Traceback'
)
self
.
assertRegex
(
err_out
.
getvalue
(),
r'import bad
\
)
sy
ntax'
)
self
.
assertRegex
(
err_out
.
getvalue
(),
r'import bad
-
syntax'
)
self
.
assertRegex
(
err_out
.
getvalue
(),
'SyntaxError'
)
def
test_addpackage_import_bad_exec
(
self
):
...
...
Misc/NEWS.d/next/Core and Builtins/2018-04-18-12-23-30.bpo-33306.tSM3cp.rst
0 → 100644
View file @
94cf308e
Improved syntax error messages for unbalanced parentheses.
Parser/tokenizer.c
View file @
94cf308e
...
...
@@ -1842,12 +1842,44 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end)
case
'('
:
case
'['
:
case
'{'
:
#ifndef PGEN
if
(
tok
->
level
>=
MAXLEVEL
)
{
return
syntaxerror
(
tok
,
"too many nested parentheses"
);
}
tok
->
parenstack
[
tok
->
level
]
=
c
;
tok
->
parenlinenostack
[
tok
->
level
]
=
tok
->
lineno
;
#endif
tok
->
level
++
;
break
;
case
')'
:
case
']'
:
case
'}'
:
#ifndef PGEN
if
(
!
tok
->
level
)
{
return
syntaxerror
(
tok
,
"unmatched '%c'"
,
c
);
}
#endif
tok
->
level
--
;
#ifndef PGEN
int
opening
=
tok
->
parenstack
[
tok
->
level
];
if
(
!
((
opening
==
'('
&&
c
==
')'
)
||
(
opening
==
'['
&&
c
==
']'
)
||
(
opening
==
'{'
&&
c
==
'}'
)))
{
if
(
tok
->
parenlinenostack
[
tok
->
level
]
!=
tok
->
lineno
)
{
return
syntaxerror
(
tok
,
"closing parenthesis '%c' does not match "
"opening parenthesis '%c' on line %d"
,
c
,
opening
,
tok
->
parenlinenostack
[
tok
->
level
]);
}
else
{
return
syntaxerror
(
tok
,
"closing parenthesis '%c' does not match "
"opening parenthesis '%c'"
,
c
,
opening
);
}
}
#endif
break
;
}
...
...
Parser/tokenizer.h
View file @
94cf308e
...
...
@@ -11,6 +11,7 @@ extern "C" {
#include "token.h"
/* For token types */
#define MAXINDENT 100
/* Max indentation level */
#define MAXLEVEL 200
/* Max parentheses level */
enum
decoding_state
{
STATE_INIT
,
...
...
@@ -39,14 +40,16 @@ struct tok_state {
int
lineno
;
/* Current line number */
int
level
;
/* () [] {} Parentheses nesting level */
/* Used to allow free continuations inside them */
/* Stuff for checking on different tab sizes */
#ifndef PGEN
char
parenstack
[
MAXLEVEL
];
int
parenlinenostack
[
MAXLEVEL
];
/* pgen doesn't have access to Python codecs, it cannot decode the input
filename. The bytes filename might be kept, but it is only used by
indenterror() and it is not really needed: pgen only compiles one file
(Grammar/Grammar). */
PyObject
*
filename
;
#endif
/* Stuff for checking on different tab sizes */
int
altindstack
[
MAXINDENT
];
/* Stack of alternate indents */
/* Stuff for PEP 0263 */
enum
decoding_state
decoding_state
;
...
...
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