mirror of
https://github.com/astral-sh/ruff
synced 2026-01-09 15:44:22 -05:00
Implement template strings (#17851)
This PR implements template strings (t-strings) in the parser and formatter for Ruff. Minimal changes necessary to compile were made in other parts of the code (e.g. ty, the linter, etc.). These will be covered properly in follow-up PRs.
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
# parse_options: {"target-version": "3.14"}
|
||||
t"{}"
|
||||
t"{ }"
|
||||
@@ -0,0 +1,2 @@
|
||||
# parse_options: {"target-version": "3.14"}
|
||||
t"{x!z}"
|
||||
@@ -0,0 +1,3 @@
|
||||
# parse_options: {"target-version": "3.14"}
|
||||
t"{x!123}"
|
||||
t"{x!'a'}"
|
||||
@@ -0,0 +1,5 @@
|
||||
# parse_options: {"target-version": "3.14"}
|
||||
# Starred expression inside t-string has a minimum precedence of bitwise or.
|
||||
t"{*}"
|
||||
t"{*x and y}"
|
||||
t"{*yield x}"
|
||||
@@ -0,0 +1,2 @@
|
||||
# parse_options: {"target-version": "3.14"}
|
||||
t"{lambda x: x}"
|
||||
@@ -0,0 +1,6 @@
|
||||
# parse_options: {"target-version": "3.14"}
|
||||
t"{"
|
||||
t"{foo!r"
|
||||
t"{foo="
|
||||
t"{"
|
||||
t"""{"""
|
||||
@@ -0,0 +1,3 @@
|
||||
# parse_options: {"target-version": "3.14"}
|
||||
t"hello {x:"
|
||||
t"hello {x:.3f"
|
||||
@@ -1,3 +1,2 @@
|
||||
def foo(arg: int): ...
|
||||
def foo(arg: lambda x: x): ...
|
||||
def foo(arg: (x := int)): ...
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
# parse_options: {"target-version": "3.14"}
|
||||
t'Magic wand: { bag['wand'] }' # nested quotes
|
||||
t"{'\n'.join(a)}" # escape sequence
|
||||
t'''A complex trick: {
|
||||
bag['bag'] # comment
|
||||
}'''
|
||||
t"{t"{t"{t"{t"{t"{1+1}"}"}"}"}"}" # arbitrary nesting
|
||||
t"{t'''{"nested"} inner'''} outer" # nested (triple) quotes
|
||||
t"test {a \
|
||||
} more" # line continuation
|
||||
Reference in New Issue
Block a user