Content-Length: 398139 | pFad | http://github.com/Instagram/LibCST/commit/edad86ab48069d9eed49bdaa5939fada9b58c7e6

59 [native] Allow unparenthesized tuples inside f-strings · Instagram/LibCST@edad86a · GitHub
Skip to content

Commit edad86a

Browse files
committed
[native] Allow unparenthesized tuples inside f-strings
1 parent d35b6a5 commit edad86a

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

libcst/_nodes/tests/test_atom.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,69 @@ class AtomTest(CSTNodeTest):
740740
"parser": parse_expression,
741741
"expected_position": None,
742742
},
743+
# Unpacked tuple
744+
{
745+
"node": cst.FormattedString(
746+
parts=[
747+
cst.FormattedStringExpression(
748+
expression=cst.Tuple(
749+
elements=[
750+
cst.Element(
751+
value=cst.Name(
752+
value="a",
753+
),
754+
comma=cst.Comma(
755+
whitespace_before=cst.SimpleWhitespace(
756+
value="",
757+
),
758+
whitespace_after=cst.SimpleWhitespace(
759+
value=" ",
760+
),
761+
),
762+
),
763+
cst.Element(
764+
value=cst.Name(
765+
value="b",
766+
),
767+
),
768+
],
769+
lpar=[],
770+
rpar=[],
771+
),
772+
),
773+
],
774+
start="f'",
775+
end="'",
776+
),
777+
"code": "f'{a, b}'",
778+
"parser": parse_expression,
779+
"expected_position": None,
780+
},
781+
# Conditional expression
782+
{
783+
"node": cst.FormattedString(
784+
parts=[
785+
cst.FormattedStringExpression(
786+
expression=cst.IfExp(
787+
test=cst.Name(
788+
value="b",
789+
),
790+
body=cst.Name(
791+
value="a",
792+
),
793+
orelse=cst.Name(
794+
value="c",
795+
),
796+
),
797+
),
798+
],
799+
start="f'",
800+
end="'",
801+
),
802+
"code": "f'{a if b else c}'",
803+
"parser": parse_expression,
804+
"expected_position": None,
805+
},
743806
# Concatenated strings
744807
{
745808
"node": cst.ConcatenatedString(

native/libcst/src/parser/grammar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,7 @@ parser! {
13961396

13971397
rule _f_expr() -> Expression<'a>
13981398
= (g:_bare_genexp() {Expression::GeneratorExp(g)})
1399-
/ _conditional_expression()
1399+
/ star_expressions()
14001400
/ yield_expr()
14011401

14021402
rule _f_conversion() -> &'a str

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/Instagram/LibCST/commit/edad86ab48069d9eed49bdaa5939fada9b58c7e6

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy