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
09835dcd
Commit
09835dcd
authored
Sep 11, 2016
by
Eric V. Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make an f-string error message more exact and consistent.
parent
13a6d283
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
2 deletions
+3
-2
Lib/test/test_fstring.py
Lib/test/test_fstring.py
+2
-1
Python/ast.c
Python/ast.c
+1
-1
No files found.
Lib/test/test_fstring.py
View file @
09835dcd
...
@@ -182,9 +182,10 @@ f'{a * x()}'"""
...
@@ -182,9 +182,10 @@ f'{a * x()}'"""
self
.
assertEqual
(
f'
{
"#"
}
'
,
'#'
)
self
.
assertEqual
(
f'
{
"#"
}
'
,
'#'
)
self
.
assertEqual
(
f'
{
d
[
"#"
]
}
'
,
'hash'
)
self
.
assertEqual
(
f'
{
d
[
"#"
]
}
'
,
'hash'
)
self
.
assertAllRaise
(
SyntaxError
,
"f-string cannot include '#'"
,
self
.
assertAllRaise
(
SyntaxError
,
"f-string
expression part
cannot include '#'"
,
[
"f'{1#}'"
,
# error because the expression becomes "(1#)"
[
"f'{1#}'"
,
# error because the expression becomes "(1#)"
"f'{3(#)}'"
,
"f'{3(#)}'"
,
"f'{#}'"
,
])
])
def
test_many_expressions
(
self
):
def
test_many_expressions
(
self
):
...
...
Python/ast.c
View file @
09835dcd
...
@@ -4419,7 +4419,7 @@ fstring_find_expr(const char **str, const char *end, int raw, int recurse_lvl,
...
@@ -4419,7 +4419,7 @@ fstring_find_expr(const char **str, const char *end, int raw, int recurse_lvl,
}
else
if
(
ch
==
'#'
)
{
}
else
if
(
ch
==
'#'
)
{
/* Error: can't include a comment character, inside parens
/* Error: can't include a comment character, inside parens
or not. */
or not. */
ast_error
(
c
,
n
,
"f-string cannot include '#'"
);
ast_error
(
c
,
n
,
"f-string
expression part
cannot include '#'"
);
return
-
1
;
return
-
1
;
}
else
if
(
nested_depth
==
0
&&
}
else
if
(
nested_depth
==
0
&&
(
ch
==
'!'
||
ch
==
':'
||
ch
==
'}'
))
{
(
ch
==
'!'
||
ch
==
':'
||
ch
==
'}'
))
{
...
...
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