Commit abff6ab6 authored by Stefan Behnel's avatar Stefan Behnel

disable a restriction in the f-string format parser that seems arbitrary and difficult to implement

parent 06cf4ed0
......@@ -1101,8 +1101,6 @@ def p_f_string_expr(s, unicode_value, pos, starting_index):
c = unicode_value[i]
if not in_triple_quotes and not in_string:
if c == '{':
if nested_depth >= 1:
s.error("nesting of '{' in format specifier is not allowed")
nested_depth += 1
elif c == '}':
if nested_depth > 0:
......
......@@ -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:#{3 != {4:5} and width}x}', ' 0xa')
self.assertEqual(f'{10:#{3 != {4:5} and width}x}', ' 0xa')
self.assertAllRaise(SyntaxError, "f-string: expecting '}'",
["""f'{"s"!r{":10"}}'""",
......@@ -315,10 +315,13 @@ f'{a * x()}'"""
"f'{4:{/5}}'",
])
self.assertAllRaise(SyntaxError, "f-string: expressions nested too deeply",
[# Can't nest format specifiers.
"f'result: {value:{width:{0}}.{precision:1}}'",
])
# CYTHON: The nesting restriction seems rather arbitrary. Ignoring it for now and instead test that it works.
if not IS_PY26:
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',
[# No expansion inside conversion or for
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment