From ff9ed2e8e4572dad2996d07e975b274afcb018e6 Mon Sep 17 00:00:00 2001 From: Benjamin Woodruff Date: Tue, 6 Aug 2019 16:34:19 -0700 Subject: [PATCH] Change FormattedString's end field to a Literal I noticed this while working on the documentation. I think this predated pyre's Literal support. I only did this for `end` and not `start`, because there's a large combinatorial set of valid `start` values. If we wanted to better type `start`, we should probably first separate the prefix from the opening quotes. --- libcst/_nodes/_expression.py | 2 +- libcst/_nodes/tests/test_atom.py | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/libcst/_nodes/_expression.py b/libcst/_nodes/_expression.py index 34599ac2..cd0b3b86 100644 --- a/libcst/_nodes/_expression.py +++ b/libcst/_nodes/_expression.py @@ -763,7 +763,7 @@ class FormattedString(_BasePrefixedString): start: str = 'f"' #: The trailing quote. This must match the type of quote used in ``start``. - end: str = '"' + end: Literal['"', "'", '"""', "'''"] = '"' lpar: Sequence[LeftParen] = () #: Sequence of parenthesis for precidence dictation. diff --git a/libcst/_nodes/tests/test_atom.py b/libcst/_nodes/tests/test_atom.py index c780cf60..e12f2d2c 100644 --- a/libcst/_nodes/tests/test_atom.py +++ b/libcst/_nodes/tests/test_atom.py @@ -839,12 +839,6 @@ class AtomTest(CSTNodeTest): ), "expected_re": "must have matching enclosing quotes", }, - { - "get_node": ( - lambda: cst.FormattedString(start="f'''", parts=(), end="''") - ), - "expected_re": "must have matching enclosing quotes", - }, { "get_node": ( lambda: cst.ConcatenatedString(