Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
abff6ab6
Commit
abff6ab6
authored
Mar 24, 2016
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
disable a restriction in the f-string format parser that seems arbitrary and difficult to implement
parent
06cf4ed0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
7 deletions
+8
-7
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+0
-2
tests/run/test_fstring.pyx
tests/run/test_fstring.pyx
+8
-5
No files found.
Cython/Compiler/Parsing.py
View file @
abff6ab6
...
@@ -1101,8 +1101,6 @@ def p_f_string_expr(s, unicode_value, pos, starting_index):
...
@@ -1101,8 +1101,6 @@ def p_f_string_expr(s, unicode_value, pos, starting_index):
c
=
unicode_value
[
i
]
c
=
unicode_value
[
i
]
if
not
in_triple_quotes
and
not
in_string
:
if
not
in_triple_quotes
and
not
in_string
:
if
c
==
'{'
:
if
c
==
'{'
:
if
nested_depth
>=
1
:
s
.
error
(
"nesting of '{' in format specifier is not allowed"
)
nested_depth
+=
1
nested_depth
+=
1
elif
c
==
'}'
:
elif
c
==
'}'
:
if
nested_depth
>
0
:
if
nested_depth
>
0
:
...
...
tests/run/test_fstring.pyx
View file @
abff6ab6
...
@@ -302,7 +302,7 @@ f'{a * x()}'"""
...
@@ -302,7 +302,7 @@ f'{a * x()}'"""
self
.
assertEqual
(
f'
{
10
:
{
"#"
}
1
{
0
}{
"x"
}}
'
,
' 0xa'
)
self
.
assertEqual
(
f'
{
10
:
{
"#"
}
1
{
0
}{
"x"
}}
'
,
' 0xa'
)
self
.
assertEqual
(
f'
{
-
10
:
-
{
"#"
}
1
{
0
}
x
}
'
,
' -0xa'
)
self
.
assertEqual
(
f'
{
-
10
:
-
{
"#"
}
1
{
0
}
x
}
'
,
' -0xa'
)
self
.
assertEqual
(
f'
{
-
10
:
{
"-"
}
#
{
1
}
0
{
"x"
}}
'
,
' -0xa'
)
self
.
assertEqual
(
f'
{
-
10
:
{
"-"
}
#
{
1
}
0
{
"x"
}}
'
,
' -0xa'
)
#
self.assertEqual(f'{10:#{3 != {4:5} and width}x}', ' 0xa')
self
.
assertEqual
(
f'
{
10
:
#
{
3
!=
{
4
:
5
}
and
width
}
x
}
'
,
' 0xa'
)
self
.
assertAllRaise
(
SyntaxError
,
"f-string: expecting '}'"
,
self
.
assertAllRaise
(
SyntaxError
,
"f-string: expecting '}'"
,
[
"""f'{"s"!r{":10"}}'"""
,
[
"""f'{"s"!r{":10"}}'"""
,
...
@@ -315,10 +315,13 @@ f'{a * x()}'"""
...
@@ -315,10 +315,13 @@ f'{a * x()}'"""
"f'{4:{/5}}'"
,
"f'{4:{/5}}'"
,
])
])
self
.
assertAllRaise
(
SyntaxError
,
"f-string: expressions nested too deeply"
,
# CYTHON: The nesting restriction seems rather arbitrary. Ignoring it for now and instead test that it works.
[
# Can't nest format specifiers.
if
not
IS_PY26
:
"f'result: {value:{width:{0}}.{precision:1}}'"
,
self
.
assertEqual
(
f'result:
{
value
:
{
width
:
{
0
}}
.
{
precision
:
1
}}
'
,
'result: 12.35'
)
])
#self.assertAllRaise(SyntaxError, "f-string: expressions nested too deeply",
# [# Can't nest format specifiers.
# "f'result: {value:{width:{0}}.{precision:1}}'",
# ])
self
.
assertAllRaise
(
SyntaxError
,
'f-string: invalid conversion character'
,
self
.
assertAllRaise
(
SyntaxError
,
'f-string: invalid conversion character'
,
[
# No expansion inside conversion or for
[
# No expansion inside conversion or for
...
...
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