f-string syntax in Python 3.8 was enhanced

See e.g. https://twitter.com/raymondh/status/1135253771846471680
This commit is contained in:
Dave Halter
2019-06-02 22:48:47 +02:00
parent 917b4421f3
commit 6cdd47fe2b
3 changed files with 7 additions and 3 deletions

View File

@@ -153,5 +153,5 @@ strings: (STRING | fstring)+
fstring: FSTRING_START fstring_content* FSTRING_END
fstring_content: FSTRING_STRING | fstring_expr
fstring_conversion: '!' NAME
fstring_expr: '{' testlist [ fstring_conversion ] [ fstring_format_spec ] '}'
fstring_expr: '{' testlist ['='] [ fstring_conversion ] [ fstring_format_spec ] '}'
fstring_format_spec: ':' fstring_content*

View File

@@ -146,7 +146,7 @@ FAILING_EXAMPLES = [
# Now nested parsing
"f'{continue}'",
"f'{1;1}'",
"f'{a=3}'",
"f'{a*=3}'",
"f'{b\"\" \"\"}'",
]

View File

@@ -7,7 +7,7 @@ from parso.python.tokenize import tokenize
@pytest.fixture
def grammar():
return load_grammar(version='3.6')
return load_grammar(version='3.8')
@pytest.mark.parametrize(
@@ -31,6 +31,10 @@ def grammar():
'{{{1}',
'1{{2{{3',
'}}',
# New Python 3.8 syntax f'{a=}'
'{a=}',
'{a()=}',
]
)
def test_valid(code, grammar):