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): ...@@ -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:
......
...@@ -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
......
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