mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-08 12:48:07 +00:00
Disallow implicit concatenation of t-strings and other string types (#19485)
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks-instrumented (push) Blocked by required conditions
CI / benchmarks-walltime (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
[ty Playground] Release / publish (push) Waiting to run
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks-instrumented (push) Blocked by required conditions
CI / benchmarks-walltime (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
[ty Playground] Release / publish (push) Waiting to run
As of [this cpython PR](https://github.com/python/cpython/pull/135996), it is not allowed to concatenate t-strings with non-t-strings, implicitly or explicitly. Expressions such as `"foo" t"{bar}"` are now syntax errors. This PR updates some AST nodes and parsing to reflect this change. The structural change is that `TStringPart` is no longer needed, since, as in the case of `BytesStringLiteral`, the only possibilities are that we have a single `TString` or a vector of such (representing an implicit concatenation of t-strings). This removes a level of nesting from many AST expressions (which is what all the snapshot changes reflect), and simplifies some logic in the implementation of visitors, for example. The other change of note is in the parser. When we meet an implicit concatenation of string-like literals, we now count the number of t-string literals. If these do not exhaust the total number of implicitly concatenated pieces, then we emit a syntax error. To recover from this syntax error, we encode any t-string pieces as _invalid_ string literals (which means we flag them as invalid, record their range, and record the value as `""`). Note that if at least one of the pieces is an f-string we prefer to parse the entire string as an f-string; otherwise we parse it as a string. This logic is exactly the same as how we currently treat `BytesStringLiteral` parsing and error recovery - and carries with it the same pros and cons. Finally, note that I have not implemented any changes in the implementation of the formatter. As far as I can tell, none are needed. I did change a few of the fixtures so that we are always concatenating t-strings with t-strings.
This commit is contained in:
parent
df5eba7583
commit
008bbfdf5a
75 changed files with 4509 additions and 6294 deletions
|
@ -25,5 +25,5 @@ def my_func():
|
|||
|
||||
# t-strings - all ok
|
||||
t"0.0.0.0"
|
||||
"0.0.0.0" t"0.0.0.0{expr}0.0.0.0"
|
||||
"0.0.0.0" f"0.0.0.0{expr}0.0.0.0" t"0.0.0.0{expr}0.0.0.0"
|
||||
t"0.0.0.0" t"0.0.0.0{expr}0.0.0.0"
|
||||
t"0.0.0.0" t"0.0.0.0{expr}0.0.0.0" t"0.0.0.0{expr}0.0.0.0"
|
||||
|
|
|
@ -708,23 +708,10 @@ pub struct ComparableTString<'a> {
|
|||
}
|
||||
|
||||
impl<'a> From<&'a ast::TStringValue> for ComparableTString<'a> {
|
||||
// The approach taken below necessarily deviates from the
|
||||
// corresponding implementation for [`ast::FStringValue`].
|
||||
// The reason is that a t-string value is composed of _three_
|
||||
// non-comparable parts: literals, f-string expressions, and
|
||||
// t-string interpolations. Since we have merged the AST nodes
|
||||
// that capture f-string expressions and t-string interpolations
|
||||
// into the shared [`ast::InterpolatedElement`], we must
|
||||
// be careful to distinguish between them here.
|
||||
// We model a [`ComparableTString`] on the actual
|
||||
// [CPython implementation] of a `string.templatelib.Template` object.
|
||||
//
|
||||
// Consequently, we model a [`ComparableTString`] on the actual
|
||||
// [CPython implementation] of a `string.templatelib.Template` object:
|
||||
// it is composed of `strings` and `interpolations`. In CPython,
|
||||
// the `strings` field is a tuple of honest strings (since f-strings
|
||||
// are evaluated). Our `strings` field will house both f-string
|
||||
// expressions and string literals.
|
||||
//
|
||||
// Finally, as in CPython, we must be careful to ensure that the length
|
||||
// As in CPython, we must be careful to ensure that the length
|
||||
// of `strings` is always one more than the length of `interpolations` -
|
||||
// that way we can recover the original reading order by interleaving
|
||||
// starting with `strings`. This is how we can tell the
|
||||
|
@ -768,19 +755,6 @@ impl<'a> From<&'a ast::TStringValue> for ComparableTString<'a> {
|
|||
.push(ComparableInterpolatedStringElement::Literal("".into()));
|
||||
}
|
||||
|
||||
fn push_fstring_expression(&mut self, expression: &'a ast::InterpolatedElement) {
|
||||
if let Some(ComparableInterpolatedStringElement::Literal(last_literal)) =
|
||||
self.strings.last()
|
||||
{
|
||||
// Recall that we insert empty strings after
|
||||
// each interpolation. If we encounter an f-string
|
||||
// expression, we replace the empty string with it.
|
||||
if last_literal.is_empty() {
|
||||
self.strings.pop();
|
||||
}
|
||||
}
|
||||
self.strings.push(expression.into());
|
||||
}
|
||||
fn push_tstring_interpolation(&mut self, expression: &'a ast::InterpolatedElement) {
|
||||
self.interpolations.push(expression.into());
|
||||
self.start_new_literal();
|
||||
|
@ -789,13 +763,7 @@ impl<'a> From<&'a ast::TStringValue> for ComparableTString<'a> {
|
|||
|
||||
let mut collector = Collector::default();
|
||||
|
||||
for part in value {
|
||||
match part {
|
||||
ast::TStringPart::Literal(string_literal) => {
|
||||
collector.push_literal(&string_literal.value);
|
||||
}
|
||||
ast::TStringPart::TString(fstring) => {
|
||||
for element in &fstring.elements {
|
||||
for element in value.elements() {
|
||||
match element {
|
||||
ast::InterpolatedStringElement::Literal(literal) => {
|
||||
collector.push_literal(&literal.value);
|
||||
|
@ -805,21 +773,6 @@ impl<'a> From<&'a ast::TStringValue> for ComparableTString<'a> {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ast::TStringPart::FString(fstring) => {
|
||||
for element in &fstring.elements {
|
||||
match element {
|
||||
ast::InterpolatedStringElement::Literal(literal) => {
|
||||
collector.push_literal(&literal.value);
|
||||
}
|
||||
ast::InterpolatedStringElement::Interpolation(expression) => {
|
||||
collector.push_fstring_expression(expression);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Self {
|
||||
strings: collector.strings.into_boxed_slice(),
|
||||
|
|
|
@ -320,7 +320,7 @@ pub enum StringLikePartIter<'a> {
|
|||
String(std::slice::Iter<'a, ast::StringLiteral>),
|
||||
Bytes(std::slice::Iter<'a, ast::BytesLiteral>),
|
||||
FString(std::slice::Iter<'a, ast::FStringPart>),
|
||||
TString(std::slice::Iter<'a, ast::TStringPart>),
|
||||
TString(std::slice::Iter<'a, ast::TString>),
|
||||
}
|
||||
|
||||
impl<'a> Iterator for StringLikePartIter<'a> {
|
||||
|
@ -339,16 +339,7 @@ impl<'a> Iterator for StringLikePartIter<'a> {
|
|||
ast::FStringPart::FString(f_string) => StringLikePart::FString(f_string),
|
||||
}
|
||||
}
|
||||
StringLikePartIter::TString(inner) => {
|
||||
let part = inner.next()?;
|
||||
match part {
|
||||
ast::TStringPart::Literal(string_literal) => {
|
||||
StringLikePart::String(string_literal)
|
||||
}
|
||||
ast::TStringPart::TString(t_string) => StringLikePart::TString(t_string),
|
||||
ast::TStringPart::FString(f_string) => StringLikePart::FString(f_string),
|
||||
}
|
||||
}
|
||||
StringLikePartIter::TString(inner) => StringLikePart::TString(inner.next()?),
|
||||
};
|
||||
|
||||
Some(part)
|
||||
|
@ -378,16 +369,7 @@ impl DoubleEndedIterator for StringLikePartIter<'_> {
|
|||
ast::FStringPart::FString(f_string) => StringLikePart::FString(f_string),
|
||||
}
|
||||
}
|
||||
StringLikePartIter::TString(inner) => {
|
||||
let part = inner.next_back()?;
|
||||
match part {
|
||||
ast::TStringPart::Literal(string_literal) => {
|
||||
StringLikePart::String(string_literal)
|
||||
}
|
||||
ast::TStringPart::TString(t_string) => StringLikePart::TString(t_string),
|
||||
ast::TStringPart::FString(f_string) => StringLikePart::FString(f_string),
|
||||
}
|
||||
}
|
||||
StringLikePartIter::TString(inner) => StringLikePart::TString(inner.next_back()?),
|
||||
};
|
||||
|
||||
Some(part)
|
||||
|
|
|
@ -1274,6 +1274,7 @@ impl Truthiness {
|
|||
Self::Unknown
|
||||
}
|
||||
}
|
||||
Expr::TString(_) => Self::Truthy,
|
||||
Expr::List(ast::ExprList { elts, .. })
|
||||
| Expr::Set(ast::ExprSet { elts, .. })
|
||||
| Expr::Tuple(ast::ExprTuple { elts, .. }) => {
|
||||
|
@ -1362,6 +1363,7 @@ fn is_non_empty_f_string(expr: &ast::ExprFString) -> bool {
|
|||
Expr::EllipsisLiteral(_) => true,
|
||||
Expr::List(_) => true,
|
||||
Expr::Tuple(_) => true,
|
||||
Expr::TString(_) => true,
|
||||
|
||||
// These expressions must resolve to the inner expression.
|
||||
Expr::If(ast::ExprIf { body, orelse, .. }) => inner(body) && inner(orelse),
|
||||
|
@ -1386,7 +1388,6 @@ fn is_non_empty_f_string(expr: &ast::ExprFString) -> bool {
|
|||
// These literals may or may not be empty.
|
||||
Expr::FString(f_string) => is_non_empty_f_string(f_string),
|
||||
// These literals may or may not be empty.
|
||||
Expr::TString(f_string) => is_non_empty_t_string(f_string),
|
||||
Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) => !value.is_empty(),
|
||||
Expr::BytesLiteral(ast::ExprBytesLiteral { value, .. }) => !value.is_empty(),
|
||||
}
|
||||
|
@ -1403,76 +1404,6 @@ fn is_non_empty_f_string(expr: &ast::ExprFString) -> bool {
|
|||
})
|
||||
}
|
||||
|
||||
/// Returns `true` if the expression definitely resolves to a non-empty string, when used as an
|
||||
/// f-string expression, or `false` if the expression may resolve to an empty string.
|
||||
fn is_non_empty_t_string(expr: &ast::ExprTString) -> bool {
|
||||
fn inner(expr: &Expr) -> bool {
|
||||
match expr {
|
||||
// When stringified, these expressions are always non-empty.
|
||||
Expr::Lambda(_) => true,
|
||||
Expr::Dict(_) => true,
|
||||
Expr::Set(_) => true,
|
||||
Expr::ListComp(_) => true,
|
||||
Expr::SetComp(_) => true,
|
||||
Expr::DictComp(_) => true,
|
||||
Expr::Compare(_) => true,
|
||||
Expr::NumberLiteral(_) => true,
|
||||
Expr::BooleanLiteral(_) => true,
|
||||
Expr::NoneLiteral(_) => true,
|
||||
Expr::EllipsisLiteral(_) => true,
|
||||
Expr::List(_) => true,
|
||||
Expr::Tuple(_) => true,
|
||||
|
||||
// These expressions must resolve to the inner expression.
|
||||
Expr::If(ast::ExprIf { body, orelse, .. }) => inner(body) && inner(orelse),
|
||||
Expr::Named(ast::ExprNamed { value, .. }) => inner(value),
|
||||
|
||||
// These expressions are complex. We can't determine whether they're empty or not.
|
||||
Expr::BoolOp(ast::ExprBoolOp { .. }) => false,
|
||||
Expr::BinOp(ast::ExprBinOp { .. }) => false,
|
||||
Expr::UnaryOp(ast::ExprUnaryOp { .. }) => false,
|
||||
Expr::Generator(_) => false,
|
||||
Expr::Await(_) => false,
|
||||
Expr::Yield(_) => false,
|
||||
Expr::YieldFrom(_) => false,
|
||||
Expr::Call(_) => false,
|
||||
Expr::Attribute(_) => false,
|
||||
Expr::Subscript(_) => false,
|
||||
Expr::Starred(_) => false,
|
||||
Expr::Name(_) => false,
|
||||
Expr::Slice(_) => false,
|
||||
Expr::IpyEscapeCommand(_) => false,
|
||||
|
||||
// These literals may or may not be empty.
|
||||
Expr::FString(f_string) => is_non_empty_f_string(f_string),
|
||||
// These literals may or may not be empty.
|
||||
Expr::TString(t_string) => is_non_empty_t_string(t_string),
|
||||
Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) => !value.is_empty(),
|
||||
Expr::BytesLiteral(ast::ExprBytesLiteral { value, .. }) => !value.is_empty(),
|
||||
}
|
||||
}
|
||||
|
||||
expr.value.iter().any(|part| match part {
|
||||
ast::TStringPart::Literal(string_literal) => !string_literal.is_empty(),
|
||||
ast::TStringPart::TString(t_string) => {
|
||||
t_string.elements.iter().all(|element| match element {
|
||||
ast::InterpolatedStringElement::Literal(string_literal) => {
|
||||
!string_literal.is_empty()
|
||||
}
|
||||
ast::InterpolatedStringElement::Interpolation(t_string) => {
|
||||
inner(&t_string.expression)
|
||||
}
|
||||
})
|
||||
}
|
||||
ast::TStringPart::FString(f_string) => {
|
||||
f_string.elements.iter().all(|element| match element {
|
||||
InterpolatedStringElement::Literal(string_literal) => !string_literal.is_empty(),
|
||||
InterpolatedStringElement::Interpolation(f_string) => inner(&f_string.expression),
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns `true` if the expression definitely resolves to the empty string, when used as an f-string
|
||||
/// expression.
|
||||
fn is_empty_f_string(expr: &ast::ExprFString) -> bool {
|
||||
|
|
|
@ -171,20 +171,10 @@ impl ast::ExprTString {
|
|||
node_index: _,
|
||||
} = self;
|
||||
|
||||
for t_string_part in value {
|
||||
match t_string_part {
|
||||
ast::TStringPart::Literal(string_literal) => {
|
||||
visitor.visit_string_literal(string_literal);
|
||||
}
|
||||
ast::TStringPart::FString(f_string) => {
|
||||
visitor.visit_f_string(f_string);
|
||||
}
|
||||
ast::TStringPart::TString(t_string) => {
|
||||
for t_string in value {
|
||||
visitor.visit_t_string(t_string);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ExprStringLiteral {
|
||||
|
|
|
@ -597,8 +597,8 @@ impl ExprTString {
|
|||
/// otherwise.
|
||||
pub const fn as_single_part_tstring(&self) -> Option<&TString> {
|
||||
match &self.value.inner {
|
||||
TStringValueInner::Single(TStringPart::TString(tstring)) => Some(tstring),
|
||||
_ => None,
|
||||
TStringValueInner::Single(tstring) => Some(tstring),
|
||||
TStringValueInner::Concatenated(_) => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -614,7 +614,7 @@ impl TStringValue {
|
|||
/// Creates a new t-string literal with a single [`TString`] part.
|
||||
pub fn single(value: TString) -> Self {
|
||||
Self {
|
||||
inner: TStringValueInner::Single(TStringPart::TString(value)),
|
||||
inner: TStringValueInner::Single(value),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -625,7 +625,7 @@ impl TStringValue {
|
|||
///
|
||||
/// Panics if `values` has less than 2 elements.
|
||||
/// Use [`TStringValue::single`] instead.
|
||||
pub fn concatenated(values: Vec<TStringPart>) -> Self {
|
||||
pub fn concatenated(values: Vec<TString>) -> Self {
|
||||
assert!(
|
||||
values.len() > 1,
|
||||
"Use `TStringValue::single` to create single-part t-strings"
|
||||
|
@ -640,78 +640,52 @@ impl TStringValue {
|
|||
matches!(self.inner, TStringValueInner::Concatenated(_))
|
||||
}
|
||||
|
||||
/// Returns a slice of all the [`TStringPart`]s contained in this value.
|
||||
pub fn as_slice(&self) -> &[TStringPart] {
|
||||
/// Returns a slice of all the [`TString`]s contained in this value.
|
||||
pub fn as_slice(&self) -> &[TString] {
|
||||
match &self.inner {
|
||||
TStringValueInner::Single(part) => std::slice::from_ref(part),
|
||||
TStringValueInner::Concatenated(parts) => parts,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a mutable slice of all the [`TStringPart`]s contained in this value.
|
||||
fn as_mut_slice(&mut self) -> &mut [TStringPart] {
|
||||
/// Returns a mutable slice of all the [`TString`]s contained in this value.
|
||||
fn as_mut_slice(&mut self) -> &mut [TString] {
|
||||
match &mut self.inner {
|
||||
TStringValueInner::Single(part) => std::slice::from_mut(part),
|
||||
TStringValueInner::Concatenated(parts) => parts,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns an iterator over all the [`TStringPart`]s contained in this value.
|
||||
pub fn iter(&self) -> Iter<TStringPart> {
|
||||
/// Returns an iterator over all the [`TString`]s contained in this value.
|
||||
pub fn iter(&self) -> Iter<TString> {
|
||||
self.as_slice().iter()
|
||||
}
|
||||
|
||||
/// Returns an iterator over all the [`TStringPart`]s contained in this value
|
||||
/// Returns an iterator over all the [`TString`]s contained in this value
|
||||
/// that allows modification.
|
||||
pub fn iter_mut(&mut self) -> IterMut<TStringPart> {
|
||||
pub fn iter_mut(&mut self) -> IterMut<TString> {
|
||||
self.as_mut_slice().iter_mut()
|
||||
}
|
||||
|
||||
/// Returns an iterator over the [`StringLiteral`] parts contained in this value.
|
||||
///
|
||||
/// Note that this doesn't recurse into the t-string parts. For example,
|
||||
///
|
||||
/// ```python
|
||||
/// "foo" t"bar {x}" "baz" t"qux"
|
||||
/// ```
|
||||
///
|
||||
/// Here, the string literal parts returned would be `"foo"` and `"baz"`.
|
||||
pub fn literals(&self) -> impl Iterator<Item = &StringLiteral> {
|
||||
self.iter().filter_map(|part| part.as_literal())
|
||||
}
|
||||
|
||||
/// Returns an iterator over the [`TString`] parts contained in this value.
|
||||
///
|
||||
/// Note that this doesn't recurse into the t-string parts. For example,
|
||||
///
|
||||
/// ```python
|
||||
/// "foo" t"bar {x}" "baz" t"qux"
|
||||
/// ```
|
||||
///
|
||||
/// Here, the t-string parts returned would be `f"bar {x}"` and `f"qux"`.
|
||||
pub fn t_strings(&self) -> impl Iterator<Item = &TString> {
|
||||
self.iter().filter_map(|part| part.as_t_string())
|
||||
}
|
||||
|
||||
/// Returns an iterator over all the [`InterpolatedStringElement`] contained in this value.
|
||||
///
|
||||
/// An t-string element is what makes up an [`TString`] i.e., it is either a
|
||||
/// An interpolated string element is what makes up an [`TString`] i.e., it is either a
|
||||
/// string literal or an interpolation. In the following example,
|
||||
///
|
||||
/// ```python
|
||||
/// "foo" t"bar {x}" "baz" t"qux"
|
||||
/// t"foo" t"bar {x}" t"baz" t"qux"
|
||||
/// ```
|
||||
///
|
||||
/// The t-string elements returned would be string literal (`"bar "`),
|
||||
/// The interpolated string elements returned would be string literal (`"bar "`),
|
||||
/// interpolation (`x`) and string literal (`"qux"`).
|
||||
pub fn elements(&self) -> impl Iterator<Item = &InterpolatedStringElement> {
|
||||
self.t_strings().flat_map(|fstring| fstring.elements.iter())
|
||||
self.iter().flat_map(|tstring| tstring.elements.iter())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoIterator for &'a TStringValue {
|
||||
type Item = &'a TStringPart;
|
||||
type IntoIter = Iter<'a, TStringPart>;
|
||||
type Item = &'a TString;
|
||||
type IntoIter = Iter<'a, TString>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.iter()
|
||||
|
@ -719,8 +693,8 @@ impl<'a> IntoIterator for &'a TStringValue {
|
|||
}
|
||||
|
||||
impl<'a> IntoIterator for &'a mut TStringValue {
|
||||
type Item = &'a mut TStringPart;
|
||||
type IntoIter = IterMut<'a, TStringPart>;
|
||||
type Item = &'a mut TString;
|
||||
type IntoIter = IterMut<'a, TString>;
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.iter_mut()
|
||||
}
|
||||
|
@ -731,43 +705,10 @@ impl<'a> IntoIterator for &'a mut TStringValue {
|
|||
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
|
||||
enum TStringValueInner {
|
||||
/// A single t-string i.e., `t"foo"`.
|
||||
///
|
||||
/// This is always going to be `TStringPart::TString` variant which is
|
||||
/// maintained by the `TStringValue::single` constructor.
|
||||
Single(TStringPart),
|
||||
Single(TString),
|
||||
|
||||
/// An implicitly concatenated t-string i.e., `"foo" t"bar {x}"`.
|
||||
Concatenated(Vec<TStringPart>),
|
||||
}
|
||||
|
||||
/// An t-string part which is either a string literal, an f-string,
|
||||
/// or a t-string.
|
||||
#[derive(Clone, Debug, PartialEq, is_macro::Is)]
|
||||
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
|
||||
pub enum TStringPart {
|
||||
Literal(StringLiteral),
|
||||
FString(FString),
|
||||
TString(TString),
|
||||
}
|
||||
|
||||
impl TStringPart {
|
||||
pub fn quote_style(&self) -> Quote {
|
||||
match self {
|
||||
Self::Literal(string_literal) => string_literal.flags.quote_style(),
|
||||
Self::FString(f_string) => f_string.flags.quote_style(),
|
||||
Self::TString(t_string) => t_string.flags.quote_style(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Ranged for TStringPart {
|
||||
fn range(&self) -> TextRange {
|
||||
match self {
|
||||
TStringPart::Literal(string_literal) => string_literal.range(),
|
||||
TStringPart::FString(f_string) => f_string.range(),
|
||||
TStringPart::TString(t_string) => t_string.range(),
|
||||
}
|
||||
}
|
||||
/// An implicitly concatenated t-string i.e., `t"foo" t"bar {x}"`.
|
||||
Concatenated(Vec<TString>),
|
||||
}
|
||||
|
||||
pub trait StringFlags: Copy {
|
||||
|
@ -1237,6 +1178,12 @@ pub struct TString {
|
|||
pub flags: TStringFlags,
|
||||
}
|
||||
|
||||
impl TString {
|
||||
pub fn quote_style(&self) -> Quote {
|
||||
self.flags.quote_style()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TString> for Expr {
|
||||
fn from(payload: TString) -> Self {
|
||||
ExprTString {
|
||||
|
|
|
@ -7,8 +7,8 @@ use crate::{
|
|||
self as ast, Alias, AnyParameterRef, Arguments, BoolOp, BytesLiteral, CmpOp, Comprehension,
|
||||
Decorator, ElifElseClause, ExceptHandler, Expr, ExprContext, FString, FStringPart,
|
||||
InterpolatedStringElement, Keyword, MatchCase, Operator, Parameter, Parameters, Pattern,
|
||||
PatternArguments, PatternKeyword, Stmt, StringLiteral, TString, TStringPart, TypeParam,
|
||||
TypeParamParamSpec, TypeParamTypeVar, TypeParamTypeVarTuple, TypeParams, UnaryOp, WithItem,
|
||||
PatternArguments, PatternKeyword, Stmt, StringLiteral, TString, TypeParam, TypeParamParamSpec,
|
||||
TypeParamTypeVar, TypeParamTypeVarTuple, TypeParams, UnaryOp, WithItem,
|
||||
};
|
||||
|
||||
/// A trait for AST visitors. Visits all nodes in the AST recursively in evaluation-order.
|
||||
|
@ -547,14 +547,8 @@ pub fn walk_expr<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, expr: &'a Expr) {
|
|||
}
|
||||
}
|
||||
Expr::TString(ast::ExprTString { value, .. }) => {
|
||||
for part in value {
|
||||
match part {
|
||||
TStringPart::Literal(string_literal) => {
|
||||
visitor.visit_string_literal(string_literal);
|
||||
}
|
||||
TStringPart::FString(f_string) => visitor.visit_f_string(f_string),
|
||||
TStringPart::TString(t_string) => visitor.visit_t_string(t_string),
|
||||
}
|
||||
for t_string in value {
|
||||
visitor.visit_t_string(t_string);
|
||||
}
|
||||
}
|
||||
Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) => {
|
||||
|
|
|
@ -533,20 +533,10 @@ pub fn walk_expr<V: Transformer + ?Sized>(visitor: &V, expr: &mut Expr) {
|
|||
}
|
||||
}
|
||||
Expr::TString(ast::ExprTString { value, .. }) => {
|
||||
for t_string_part in value.iter_mut() {
|
||||
match t_string_part {
|
||||
ast::TStringPart::Literal(string_literal) => {
|
||||
visitor.visit_string_literal(string_literal);
|
||||
}
|
||||
ast::TStringPart::FString(f_string) => {
|
||||
visitor.visit_f_string(f_string);
|
||||
}
|
||||
ast::TStringPart::TString(t_string) => {
|
||||
for t_string in value.iter_mut() {
|
||||
visitor.visit_t_string(t_string);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) => {
|
||||
for string_literal in value.iter_mut() {
|
||||
visitor.visit_string_literal(string_literal);
|
||||
|
|
|
@ -51,28 +51,12 @@ fn concatenated_fstrings_compare_equal() -> Result<(), ParseError> {
|
|||
|
||||
#[test]
|
||||
fn concatenated_tstrings_compare_equal() -> Result<(), ParseError> {
|
||||
let split_contents = r#"t"{foo!r} this" r"\n raw" t" and {bar!s} that""#;
|
||||
let split_contents = r#"t"{foo!r} this" rt"\n raw" t" and {bar!s} that""#;
|
||||
let value_contents = r#"t"{foo!r} this\\n raw and {bar!s} that""#;
|
||||
|
||||
assert_comparable(split_contents, value_contents)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn concatenated_f_and_t_strings_interwoven_compare_equal() -> Result<(), ParseError> {
|
||||
let split_contents = r#"f"{foo} this " t"{bar}" "baz""#;
|
||||
let value_contents = r#"f"{foo}" t" this {bar}" "baz""#;
|
||||
|
||||
assert_comparable(split_contents, value_contents)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn concatenated_f_and_t_strings_compare_unequal_when_swapped() -> Result<(), ParseError> {
|
||||
let f_then_t_contents = r#"f"{foo!r} this" r"\n raw" t" and {bar!s} that""#;
|
||||
let t_then_f_contents = r#"t"{foo!r} this" r"\n raw" f" and {bar!s} that""#;
|
||||
|
||||
assert_noncomparable(f_then_t_contents, t_then_f_contents)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn t_strings_literal_order_matters_compare_unequal() -> Result<(), ParseError> {
|
||||
let interp_then_literal_contents = r#"t"{foo}bar""#;
|
||||
|
@ -80,11 +64,3 @@ fn t_strings_literal_order_matters_compare_unequal() -> Result<(), ParseError> {
|
|||
|
||||
assert_noncomparable(interp_then_literal_contents, literal_then_interp_contents)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn t_strings_empty_concat_equal() -> Result<(), ParseError> {
|
||||
let empty_literal = r#""" t"hey{foo}""#;
|
||||
let empty_f_string = r#"f""t"hey{foo}""#;
|
||||
|
||||
assert_comparable(empty_literal, empty_f_string)
|
||||
}
|
||||
|
|
|
@ -5,7 +5,8 @@ expression: trace
|
|||
- ModModule
|
||||
- StmtExpr
|
||||
- ExprTString
|
||||
- StringLiteral
|
||||
- TString
|
||||
- InterpolatedStringLiteralElement
|
||||
- TString
|
||||
- InterpolatedStringLiteralElement
|
||||
- InterpolatedElement
|
||||
|
|
|
@ -4,7 +4,8 @@ expression: trace
|
|||
---
|
||||
- StmtExpr
|
||||
- ExprTString
|
||||
- StringLiteral
|
||||
- TString
|
||||
- InterpolatedStringLiteralElement
|
||||
- TString
|
||||
- InterpolatedStringLiteralElement
|
||||
- InterpolatedElement
|
||||
|
|
|
@ -148,7 +148,7 @@ fn f_strings() {
|
|||
|
||||
#[test]
|
||||
fn t_strings() {
|
||||
let source = r"'pre' t'foo {bar:.{x}f} baz'";
|
||||
let source = r"t'pre' t'foo {bar:.{x}f} baz'";
|
||||
|
||||
let trace = trace_source_order_visitation(source);
|
||||
|
||||
|
|
|
@ -157,7 +157,7 @@ fn f_strings() {
|
|||
|
||||
#[test]
|
||||
fn t_strings() {
|
||||
let source = r"'pre' t'foo {bar:.{x}f} baz'";
|
||||
let source = r"t'pre' t'foo {bar:.{x}f} baz'";
|
||||
|
||||
let trace = trace_visitation(source);
|
||||
|
||||
|
|
|
@ -1538,21 +1538,11 @@ impl<'a> Generator<'a> {
|
|||
|
||||
fn unparse_t_string_value(&mut self, value: &ast::TStringValue) {
|
||||
let mut first = true;
|
||||
for t_string_part in value {
|
||||
for t_string in value {
|
||||
self.p_delim(&mut first, " ");
|
||||
match t_string_part {
|
||||
ast::TStringPart::Literal(string_literal) => {
|
||||
self.unparse_string_literal(string_literal);
|
||||
}
|
||||
ast::TStringPart::FString(f_string) => {
|
||||
self.unparse_interpolated_string(&f_string.elements, f_string.flags.into());
|
||||
}
|
||||
ast::TStringPart::TString(t_string) => {
|
||||
self.unparse_interpolated_string(&t_string.elements, t_string.flags.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn unparse_alias(&mut self, alias: &Alias) {
|
||||
self.p_id(&alias.name);
|
||||
|
|
|
@ -104,16 +104,13 @@ f"{10 + len('bar')=}" f'{10 + len("bar")=}'
|
|||
# T-strings
|
||||
##############################################################################
|
||||
|
||||
# Escape `{` and `}` when merging a t-string with a string
|
||||
"a {not_a_variable}" t"b {10}" "c"
|
||||
|
||||
# Join, and break expressions
|
||||
t"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{
|
||||
expression
|
||||
}bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" t"cccccccccccccccccccc {20999}" "more"
|
||||
}bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" t"cccccccccccccccccccc {20999}" t"more"
|
||||
|
||||
# Join, but don't break the expressions
|
||||
t"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{expression}bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" t"cccccccccccccccccccc {20999}" "more"
|
||||
t"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{expression}bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" t"cccccccccccccccccccc {20999}" t"more"
|
||||
|
||||
t"test{
|
||||
expression
|
||||
|
@ -171,22 +168,11 @@ t"test" tR"test"
|
|||
|
||||
"single" f""""single"""
|
||||
|
||||
"single" t""""single"""
|
||||
t"single" t""""single"""
|
||||
|
||||
b"single" b"""triple"""
|
||||
|
||||
|
||||
##############################################################################
|
||||
# Don't join t-strings and f-strings
|
||||
##############################################################################
|
||||
|
||||
t"{interp}" f"{expr}"
|
||||
|
||||
f"{expr}" t"{interp}"
|
||||
|
||||
f"{expr}" "string" t"{interp}"
|
||||
|
||||
|
||||
##############################################################################
|
||||
# Join strings in with statements
|
||||
##############################################################################
|
||||
|
|
|
@ -345,7 +345,7 @@ a[
|
|||
b
|
||||
] = (
|
||||
t"ccccc{
|
||||
expression}ccccccccccc" "cccccccccccccccccccccccc" # comment
|
||||
expression}ccccccccccc" t"cccccccccccccccccccccccc" # comment
|
||||
)
|
||||
|
||||
# Same but starting with a joined string. They should both result in the same formatting.
|
||||
|
@ -361,7 +361,7 @@ a[
|
|||
aaaaaaa,
|
||||
b
|
||||
] = t"ccccc{
|
||||
expression}ccccccccccc" "ccccccccccccccccccccccccccccccccccccccccccc" # comment
|
||||
expression}ccccccccccc" t"ccccccccccccccccccccccccccccccccccccccccccc" # comment
|
||||
|
||||
|
||||
# Split an overlong target, but join the string if it fits
|
||||
|
@ -370,7 +370,7 @@ a[
|
|||
b
|
||||
].bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb = (
|
||||
t"ccccc{
|
||||
expression}ccccccccccc" "cccccccccccccccccccccccccccccc" # comment
|
||||
expression}ccccccccccc" t"cccccccccccccccccccccccccccccc" # comment
|
||||
)
|
||||
|
||||
# Split both if necessary and keep multiline
|
||||
|
@ -379,66 +379,66 @@ a[
|
|||
b
|
||||
].bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb = (
|
||||
t"ccccc{
|
||||
expression}cccccccccccccccccccccccccccccccc" "ccccccccccccccccccccccccccccccc" # comment
|
||||
expression}cccccccccccccccccccccccccccccccc" t"ccccccccccccccccccccccccccccccc" # comment
|
||||
)
|
||||
|
||||
# Don't inline t-strings that contain expressions that are guaranteed to split, e.b. because of a magic trailing comma
|
||||
aaaaaaaaaaaaaaaaaa = t"testeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee{
|
||||
[a,]
|
||||
}" "moreeeeeeeeeeeeeeeeeeee" "test" # comment
|
||||
}" t"moreeeeeeeeeeeeeeeeeeee" t"test" # comment
|
||||
|
||||
aaaaaaaaaaaaaaaaaa = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee{
|
||||
[a,]
|
||||
}" "moreeeeeeeeeeeeeeeeeeee" "test" # comment
|
||||
}" t"moreeeeeeeeeeeeeeeeeeee" t"test" # comment
|
||||
)
|
||||
|
||||
aaaaa[aaaaaaaaaaa] = t"testeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee{
|
||||
[a,]
|
||||
}" "moreeeeeeeeeeeeeeeeeeee" "test" # comment
|
||||
}" t"moreeeeeeeeeeeeeeeeeeee" t"test" # comment
|
||||
|
||||
aaaaa[aaaaaaaaaaa] = (t"testeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee{
|
||||
[a,]
|
||||
}" "moreeeeeeeeeeeeeeeeeeee" "test" # comment
|
||||
}" t"moreeeeeeeeeeeeeeeeeeee" t"test" # comment
|
||||
)
|
||||
|
||||
# Don't inline t-strings that contain commented expressions
|
||||
aaaaaaaaaaaaaaaaaa = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{[
|
||||
a # comment
|
||||
]}" "moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
]}" t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
aaaaa[aaaaaaaaaaa] = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{[
|
||||
a # comment
|
||||
]}" "moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
]}" t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
# Don't inline t-strings with multiline debug expressions:
|
||||
aaaaaaaaaaaaaaaaaa = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{
|
||||
a=}" "moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
a=}" t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
aaaaaaaaaaaaaaaaaa = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{a +
|
||||
b=}" "moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
b=}" t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
aaaaaaaaaaaaaaaaaa = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{a
|
||||
=}" "moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
=}" t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
aaaaa[aaaaaaaaaaa] = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{
|
||||
a=}" "moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
a=}" t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
aaaaa[aaaaaaaaaaa] = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{a
|
||||
=}" "moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
=}" t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -8,21 +8,21 @@ rt"Not-so-tricky \"quote"
|
|||
|
||||
# Regression test for tstrings dropping comments
|
||||
result_f = (
|
||||
'Traceback (most recent call last):\n'
|
||||
t'Traceback (most recent call last):\n'
|
||||
t' File "{__file__}", line {lineno_f+5}, in _check_recursive_traceback_display\n'
|
||||
' f()\n'
|
||||
t' f()\n'
|
||||
t' File "{__file__}", line {lineno_f+1}, in f\n'
|
||||
' f()\n'
|
||||
t' f()\n'
|
||||
t' File "{__file__}", line {lineno_f+1}, in f\n'
|
||||
' f()\n'
|
||||
t' f()\n'
|
||||
t' File "{__file__}", line {lineno_f+1}, in f\n'
|
||||
' f()\n'
|
||||
t' f()\n'
|
||||
# XXX: The following line changes depending on whether the tests
|
||||
# are run through the interactive interpreter or with -m
|
||||
# It also varies depending on the platform (stack size)
|
||||
# Fortunately, we don't care about exactness here, so we use regex
|
||||
r' \[Previous line repeated (\d+) more times\]' '\n'
|
||||
'RecursionError: maximum recursion depth exceeded\n'
|
||||
rt' \[Previous line repeated (\d+) more times\]' t'\n'
|
||||
t'RecursionError: maximum recursion depth exceeded\n'
|
||||
)
|
||||
|
||||
|
||||
|
@ -31,7 +31,7 @@ result_f = (
|
|||
(
|
||||
t'{1}'
|
||||
# comment 1
|
||||
''
|
||||
t''
|
||||
)
|
||||
|
||||
(
|
||||
|
@ -655,7 +655,7 @@ hello {
|
|||
|
||||
# Implicit concatenated t-string containing quotes
|
||||
_ = (
|
||||
'This string should change its quotes to double quotes'
|
||||
t'This string should change its quotes to double quotes'
|
||||
t'This string uses double quotes in an expression {"it's a quote"}'
|
||||
t'This t-string does not use any quotes.'
|
||||
)
|
||||
|
|
|
@ -110,16 +110,13 @@ f"{10 + len('bar')=}" f'{10 + len("bar")=}'
|
|||
# T-strings
|
||||
##############################################################################
|
||||
|
||||
# Escape `{` and `}` when merging a t-string with a string
|
||||
"a {not_a_variable}" t"b {10}" "c"
|
||||
|
||||
# Join, and break expressions
|
||||
t"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{
|
||||
expression
|
||||
}bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" t"cccccccccccccccccccc {20999}" "more"
|
||||
}bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" t"cccccccccccccccccccc {20999}" t"more"
|
||||
|
||||
# Join, but don't break the expressions
|
||||
t"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{expression}bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" t"cccccccccccccccccccc {20999}" "more"
|
||||
t"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{expression}bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" t"cccccccccccccccccccc {20999}" t"more"
|
||||
|
||||
t"test{
|
||||
expression
|
||||
|
@ -177,22 +174,11 @@ t"test" tR"test"
|
|||
|
||||
"single" f""""single"""
|
||||
|
||||
"single" t""""single"""
|
||||
t"single" t""""single"""
|
||||
|
||||
b"single" b"""triple"""
|
||||
|
||||
|
||||
##############################################################################
|
||||
# Don't join t-strings and f-strings
|
||||
##############################################################################
|
||||
|
||||
t"{interp}" f"{expr}"
|
||||
|
||||
f"{expr}" t"{interp}"
|
||||
|
||||
f"{expr}" "string" t"{interp}"
|
||||
|
||||
|
||||
##############################################################################
|
||||
# Join strings in with statements
|
||||
##############################################################################
|
||||
|
@ -521,9 +507,6 @@ f"{10 + len('bar')=}" f'{10 + len("bar")=}'
|
|||
# T-strings
|
||||
##############################################################################
|
||||
|
||||
# Escape `{` and `}` when merging a t-string with a string
|
||||
t"a {{not_a_variable}}b {10}c"
|
||||
|
||||
# Join, and break expressions
|
||||
t"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{
|
||||
expression
|
||||
|
@ -583,22 +566,11 @@ t"test" Rt"test"
|
|||
|
||||
"single" f""""single"""
|
||||
|
||||
"single" t""""single"""
|
||||
t"single" t""""single"""
|
||||
|
||||
b"single" b"""triple"""
|
||||
|
||||
|
||||
##############################################################################
|
||||
# Don't join t-strings and f-strings
|
||||
##############################################################################
|
||||
|
||||
t"{interp}" f"{expr}"
|
||||
|
||||
f"{expr}" t"{interp}"
|
||||
|
||||
f"{expr}" "string" t"{interp}"
|
||||
|
||||
|
||||
##############################################################################
|
||||
# Join strings in with statements
|
||||
##############################################################################
|
||||
|
@ -905,7 +877,7 @@ f"aaaaaaaaaaaaaaaa \
|
|||
```diff
|
||||
--- Stable
|
||||
+++ Preview
|
||||
@@ -302,9 +302,12 @@
|
||||
@@ -288,9 +288,12 @@
|
||||
##############################################################################
|
||||
# Use can_omit_optional_parentheses layout to avoid an instability where the formatter
|
||||
# picks the can_omit_optional_parentheses layout when the strings are joined.
|
||||
|
|
|
@ -351,7 +351,7 @@ a[
|
|||
b
|
||||
] = (
|
||||
t"ccccc{
|
||||
expression}ccccccccccc" "cccccccccccccccccccccccc" # comment
|
||||
expression}ccccccccccc" t"cccccccccccccccccccccccc" # comment
|
||||
)
|
||||
|
||||
# Same but starting with a joined string. They should both result in the same formatting.
|
||||
|
@ -367,7 +367,7 @@ a[
|
|||
aaaaaaa,
|
||||
b
|
||||
] = t"ccccc{
|
||||
expression}ccccccccccc" "ccccccccccccccccccccccccccccccccccccccccccc" # comment
|
||||
expression}ccccccccccc" t"ccccccccccccccccccccccccccccccccccccccccccc" # comment
|
||||
|
||||
|
||||
# Split an overlong target, but join the string if it fits
|
||||
|
@ -376,7 +376,7 @@ a[
|
|||
b
|
||||
].bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb = (
|
||||
t"ccccc{
|
||||
expression}ccccccccccc" "cccccccccccccccccccccccccccccc" # comment
|
||||
expression}ccccccccccc" t"cccccccccccccccccccccccccccccc" # comment
|
||||
)
|
||||
|
||||
# Split both if necessary and keep multiline
|
||||
|
@ -385,66 +385,66 @@ a[
|
|||
b
|
||||
].bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb = (
|
||||
t"ccccc{
|
||||
expression}cccccccccccccccccccccccccccccccc" "ccccccccccccccccccccccccccccccc" # comment
|
||||
expression}cccccccccccccccccccccccccccccccc" t"ccccccccccccccccccccccccccccccc" # comment
|
||||
)
|
||||
|
||||
# Don't inline t-strings that contain expressions that are guaranteed to split, e.b. because of a magic trailing comma
|
||||
aaaaaaaaaaaaaaaaaa = t"testeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee{
|
||||
[a,]
|
||||
}" "moreeeeeeeeeeeeeeeeeeee" "test" # comment
|
||||
}" t"moreeeeeeeeeeeeeeeeeeee" t"test" # comment
|
||||
|
||||
aaaaaaaaaaaaaaaaaa = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee{
|
||||
[a,]
|
||||
}" "moreeeeeeeeeeeeeeeeeeee" "test" # comment
|
||||
}" t"moreeeeeeeeeeeeeeeeeeee" t"test" # comment
|
||||
)
|
||||
|
||||
aaaaa[aaaaaaaaaaa] = t"testeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee{
|
||||
[a,]
|
||||
}" "moreeeeeeeeeeeeeeeeeeee" "test" # comment
|
||||
}" t"moreeeeeeeeeeeeeeeeeeee" t"test" # comment
|
||||
|
||||
aaaaa[aaaaaaaaaaa] = (t"testeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee{
|
||||
[a,]
|
||||
}" "moreeeeeeeeeeeeeeeeeeee" "test" # comment
|
||||
}" t"moreeeeeeeeeeeeeeeeeeee" t"test" # comment
|
||||
)
|
||||
|
||||
# Don't inline t-strings that contain commented expressions
|
||||
aaaaaaaaaaaaaaaaaa = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{[
|
||||
a # comment
|
||||
]}" "moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
]}" t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
aaaaa[aaaaaaaaaaa] = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{[
|
||||
a # comment
|
||||
]}" "moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
]}" t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
# Don't inline t-strings with multiline debug expressions:
|
||||
aaaaaaaaaaaaaaaaaa = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{
|
||||
a=}" "moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
a=}" t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
aaaaaaaaaaaaaaaaaa = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{a +
|
||||
b=}" "moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
b=}" t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
aaaaaaaaaaaaaaaaaa = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{a
|
||||
=}" "moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
=}" t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
aaaaa[aaaaaaaaaaa] = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{
|
||||
a=}" "moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
a=}" t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
aaaaa[aaaaaaaaaaa] = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{a
|
||||
=}" "moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
=}" t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
|
||||
|
@ -909,7 +909,7 @@ a[aaaaaaa, b] = t"ccccc{expression}ccccccccccccccccccccccccccccccccccc" # comme
|
|||
# The string gets parenthesized because it, with the inlined comment, exceeds the line length limit.
|
||||
a[aaaaaaa, b] = (
|
||||
t"ccccc{expression}ccccccccccc"
|
||||
"ccccccccccccccccccccccccccccccccccccccccccc"
|
||||
t"ccccccccccccccccccccccccccccccccccccccccccc"
|
||||
) # comment
|
||||
|
||||
|
||||
|
@ -925,7 +925,7 @@ a[
|
|||
aaaaaaa, b
|
||||
].bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb = (
|
||||
t"ccccc{expression}cccccccccccccccccccccccccccccccc"
|
||||
"ccccccccccccccccccccccccccccccc"
|
||||
t"ccccccccccccccccccccccccccccccc"
|
||||
) # comment
|
||||
|
||||
# Don't inline t-strings that contain expressions that are guaranteed to split, e.b. because of a magic trailing comma
|
||||
|
@ -935,8 +935,8 @@ aaaaaaaaaaaaaaaaaa = (
|
|||
a,
|
||||
]
|
||||
}"
|
||||
"moreeeeeeeeeeeeeeeeeeee"
|
||||
"test"
|
||||
t"moreeeeeeeeeeeeeeeeeeee"
|
||||
t"test"
|
||||
) # comment
|
||||
|
||||
aaaaaaaaaaaaaaaaaa = (
|
||||
|
@ -945,8 +945,8 @@ aaaaaaaaaaaaaaaaaa = (
|
|||
a,
|
||||
]
|
||||
}"
|
||||
"moreeeeeeeeeeeeeeeeeeee"
|
||||
"test" # comment
|
||||
t"moreeeeeeeeeeeeeeeeeeee"
|
||||
t"test" # comment
|
||||
)
|
||||
|
||||
aaaaa[aaaaaaaaaaa] = (
|
||||
|
@ -955,8 +955,8 @@ aaaaa[aaaaaaaaaaa] = (
|
|||
a,
|
||||
]
|
||||
}"
|
||||
"moreeeeeeeeeeeeeeeeeeee"
|
||||
"test"
|
||||
t"moreeeeeeeeeeeeeeeeeeee"
|
||||
t"test"
|
||||
) # comment
|
||||
|
||||
aaaaa[aaaaaaaaaaa] = (
|
||||
|
@ -965,8 +965,8 @@ aaaaa[aaaaaaaaaaa] = (
|
|||
a,
|
||||
]
|
||||
}"
|
||||
"moreeeeeeeeeeeeeeeeeeee"
|
||||
"test" # comment
|
||||
t"moreeeeeeeeeeeeeeeeeeee"
|
||||
t"test" # comment
|
||||
)
|
||||
|
||||
# Don't inline t-strings that contain commented expressions
|
||||
|
@ -976,7 +976,7 @@ aaaaaaaaaaaaaaaaaa = (
|
|||
a # comment
|
||||
]
|
||||
}"
|
||||
"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
aaaaa[aaaaaaaaaaa] = (
|
||||
|
@ -985,38 +985,38 @@ aaaaa[aaaaaaaaaaa] = (
|
|||
a # comment
|
||||
]
|
||||
}"
|
||||
"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
# Don't inline t-strings with multiline debug expressions:
|
||||
aaaaaaaaaaaaaaaaaa = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{
|
||||
a=}"
|
||||
"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
aaaaaaaaaaaaaaaaaa = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{a +
|
||||
b=}"
|
||||
"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
aaaaaaaaaaaaaaaaaa = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{a
|
||||
=}"
|
||||
"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
aaaaa[aaaaaaaaaaa] = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{
|
||||
a=}"
|
||||
"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
aaaaa[aaaaaaaaaaa] = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{a
|
||||
=}"
|
||||
"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -14,21 +14,21 @@ rt"Not-so-tricky \"quote"
|
|||
|
||||
# Regression test for tstrings dropping comments
|
||||
result_f = (
|
||||
'Traceback (most recent call last):\n'
|
||||
t'Traceback (most recent call last):\n'
|
||||
t' File "{__file__}", line {lineno_f+5}, in _check_recursive_traceback_display\n'
|
||||
' f()\n'
|
||||
t' f()\n'
|
||||
t' File "{__file__}", line {lineno_f+1}, in f\n'
|
||||
' f()\n'
|
||||
t' f()\n'
|
||||
t' File "{__file__}", line {lineno_f+1}, in f\n'
|
||||
' f()\n'
|
||||
t' f()\n'
|
||||
t' File "{__file__}", line {lineno_f+1}, in f\n'
|
||||
' f()\n'
|
||||
t' f()\n'
|
||||
# XXX: The following line changes depending on whether the tests
|
||||
# are run through the interactive interpreter or with -m
|
||||
# It also varies depending on the platform (stack size)
|
||||
# Fortunately, we don't care about exactness here, so we use regex
|
||||
r' \[Previous line repeated (\d+) more times\]' '\n'
|
||||
'RecursionError: maximum recursion depth exceeded\n'
|
||||
rt' \[Previous line repeated (\d+) more times\]' t'\n'
|
||||
t'RecursionError: maximum recursion depth exceeded\n'
|
||||
)
|
||||
|
||||
|
||||
|
@ -37,7 +37,7 @@ result_f = (
|
|||
(
|
||||
t'{1}'
|
||||
# comment 1
|
||||
''
|
||||
t''
|
||||
)
|
||||
|
||||
(
|
||||
|
@ -661,7 +661,7 @@ hello {
|
|||
|
||||
# Implicit concatenated t-string containing quotes
|
||||
_ = (
|
||||
'This string should change its quotes to double quotes'
|
||||
t'This string should change its quotes to double quotes'
|
||||
t'This string uses double quotes in an expression {"it's a quote"}'
|
||||
t'This t-string does not use any quotes.'
|
||||
)
|
||||
|
@ -761,22 +761,22 @@ rt"Not-so-tricky \"quote"
|
|||
|
||||
# Regression test for tstrings dropping comments
|
||||
result_f = (
|
||||
"Traceback (most recent call last):\n"
|
||||
t"Traceback (most recent call last):\n"
|
||||
t' File "{__file__}", line {lineno_f + 5}, in _check_recursive_traceback_display\n'
|
||||
" f()\n"
|
||||
t" f()\n"
|
||||
t' File "{__file__}", line {lineno_f + 1}, in f\n'
|
||||
" f()\n"
|
||||
t" f()\n"
|
||||
t' File "{__file__}", line {lineno_f + 1}, in f\n'
|
||||
" f()\n"
|
||||
t" f()\n"
|
||||
t' File "{__file__}", line {lineno_f + 1}, in f\n'
|
||||
" f()\n"
|
||||
t" f()\n"
|
||||
# XXX: The following line changes depending on whether the tests
|
||||
# are run through the interactive interpreter or with -m
|
||||
# It also varies depending on the platform (stack size)
|
||||
# Fortunately, we don't care about exactness here, so we use regex
|
||||
r" \[Previous line repeated (\d+) more times\]"
|
||||
"\n"
|
||||
"RecursionError: maximum recursion depth exceeded\n"
|
||||
rt" \[Previous line repeated (\d+) more times\]"
|
||||
t"\n"
|
||||
t"RecursionError: maximum recursion depth exceeded\n"
|
||||
)
|
||||
|
||||
|
||||
|
@ -785,7 +785,7 @@ result_f = (
|
|||
(
|
||||
t"{1}"
|
||||
# comment 1
|
||||
""
|
||||
t""
|
||||
)
|
||||
|
||||
(
|
||||
|
@ -1463,7 +1463,7 @@ hello {
|
|||
|
||||
# Implicit concatenated t-string containing quotes
|
||||
_ = (
|
||||
"This string should change its quotes to double quotes"
|
||||
t"This string should change its quotes to double quotes"
|
||||
t"This string uses double quotes in an expression {"it's a quote"}"
|
||||
t"This t-string does not use any quotes."
|
||||
)
|
||||
|
|
|
@ -3,4 +3,3 @@ t"{hey}"
|
|||
t'{there}'
|
||||
t"""what's
|
||||
happening?"""
|
||||
"implicitly"t"concatenated"
|
||||
|
|
|
@ -3,4 +3,3 @@ t"{hey}"
|
|||
t'{there}'
|
||||
t"""what's
|
||||
happening?"""
|
||||
"implicitly"t"concatenated"
|
||||
|
|
|
@ -17,7 +17,7 @@ t"{ foo = !s }"
|
|||
t"{ 1, 2 = }"
|
||||
t'{t"{3.1415=:.1f}":*^20}'
|
||||
|
||||
{"foo " t"bar {x + y} " "baz": 10}
|
||||
{t"foo " t"bar {x + y} " t"baz": 10}
|
||||
match foo:
|
||||
case "one":
|
||||
pass
|
||||
|
@ -44,31 +44,18 @@ t"{x=!a}"
|
|||
t"{x:.3f!r =}"
|
||||
t"{x = !r :.3f}"
|
||||
t"{x:.3f=!r}"
|
||||
"hello" t"{x}"
|
||||
t"hello" t"{x}"
|
||||
t"{x}" t"{y}"
|
||||
t"{x}" "world"
|
||||
t"{x}" t"world"
|
||||
t"Invalid args in command: {command, *args}"
|
||||
"foo" t"{x}" "bar"
|
||||
t"foo" t"{x}" t"bar"
|
||||
(
|
||||
t"a"
|
||||
t"b"
|
||||
"c"
|
||||
t"c"
|
||||
rt"d"
|
||||
fr"e"
|
||||
tr"e"
|
||||
)
|
||||
|
||||
# With unicode strings
|
||||
u"foo" t"{bar}" "baz" " some"
|
||||
"foo" t"{bar}" u"baz" " some"
|
||||
"foo" t"{bar}" "baz" u" some"
|
||||
u"foo" t"bar {baz} really" u"bar" "no"
|
||||
|
||||
|
||||
# With f-strings
|
||||
f"{this}" t"{that}"
|
||||
t"{this}"f"{that}"
|
||||
t"{this}" "that" f"{other}"
|
||||
f"one {this} two" "that" t"three {other} four"
|
||||
|
||||
# Nesting
|
||||
t"{f"{t"{this}"}"}"
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use std::cmp::Ordering;
|
||||
use std::ops::Deref;
|
||||
|
||||
use bitflags::bitflags;
|
||||
|
@ -1256,7 +1255,6 @@ impl<'src> Parser<'src> {
|
|||
// t'{there}'
|
||||
// t"""what's
|
||||
// happening?"""
|
||||
// "implicitly"t"concatenated"
|
||||
|
||||
// test_err template_strings_py313
|
||||
// # parse_options: {"target-version": "3.13"}
|
||||
|
@ -1264,7 +1262,6 @@ impl<'src> Parser<'src> {
|
|||
// t'{there}'
|
||||
// t"""what's
|
||||
// happening?"""
|
||||
// "implicitly"t"concatenated"
|
||||
let string_type = StringType::TString(
|
||||
self.parse_interpolated_string(InterpolatedStringKind::TString)
|
||||
.into(),
|
||||
|
@ -1281,7 +1278,7 @@ impl<'src> Parser<'src> {
|
|||
|
||||
match strings.len() {
|
||||
// This is not possible as the function was called by matching against a
|
||||
// `String` or `FStringStart` token.
|
||||
// `String`, `FStringStart`, or `TStringStart` token.
|
||||
0 => unreachable!("Expected to parse at least one string"),
|
||||
// We need a owned value, hence the `pop` here.
|
||||
1 => match strings.pop().unwrap() {
|
||||
|
@ -1322,22 +1319,22 @@ impl<'src> Parser<'src> {
|
|||
) -> Expr {
|
||||
assert!(strings.len() > 1);
|
||||
|
||||
let mut has_tstring = false;
|
||||
let mut has_fstring = false;
|
||||
let mut byte_literal_count = 0;
|
||||
let mut tstring_count = 0;
|
||||
for string in &strings {
|
||||
match string {
|
||||
StringType::FString(_) => has_fstring = true,
|
||||
StringType::TString(_) => has_tstring = true,
|
||||
StringType::TString(_) => tstring_count += 1,
|
||||
StringType::Bytes(_) => byte_literal_count += 1,
|
||||
StringType::Str(_) => {}
|
||||
}
|
||||
}
|
||||
let has_bytes = byte_literal_count > 0;
|
||||
let has_tstring = tstring_count > 0;
|
||||
|
||||
if has_bytes {
|
||||
match byte_literal_count.cmp(&strings.len()) {
|
||||
Ordering::Less => {
|
||||
if byte_literal_count < strings.len() {
|
||||
// TODO(dhruvmanila): This is not an ideal recovery because the parser
|
||||
// replaces the byte literals with an invalid string literal node. Any
|
||||
// downstream tools can extract the raw bytes from the range.
|
||||
|
@ -1359,7 +1356,7 @@ impl<'src> Parser<'src> {
|
|||
// Only construct a byte expression if all the literals are bytes
|
||||
// otherwise, we'll try either string, t-string, or f-string. This is to retain
|
||||
// as much information as possible.
|
||||
Ordering::Equal => {
|
||||
else {
|
||||
let mut values = Vec::with_capacity(strings.len());
|
||||
for string in strings {
|
||||
values.push(match string {
|
||||
|
@ -1373,7 +1370,33 @@ impl<'src> Parser<'src> {
|
|||
node_index: AtomicNodeIndex::dummy(),
|
||||
});
|
||||
}
|
||||
Ordering::Greater => unreachable!(),
|
||||
}
|
||||
|
||||
if has_tstring {
|
||||
if tstring_count < strings.len() {
|
||||
self.add_error(
|
||||
ParseErrorType::OtherError(
|
||||
"cannot mix t-string literals with string or bytes literals".to_string(),
|
||||
),
|
||||
range,
|
||||
);
|
||||
}
|
||||
// Only construct a t-string expression if all the literals are t-strings
|
||||
// otherwise, we'll try either string or f-string. This is to retain
|
||||
// as much information as possible.
|
||||
else {
|
||||
let mut values = Vec::with_capacity(strings.len());
|
||||
for string in strings {
|
||||
values.push(match string {
|
||||
StringType::TString(value) => value,
|
||||
_ => unreachable!("Expected `StringType::TString`"),
|
||||
});
|
||||
}
|
||||
return Expr::from(ast::ExprTString {
|
||||
value: ast::TStringValue::concatenated(values),
|
||||
range,
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1414,36 +1437,17 @@ impl<'src> Parser<'src> {
|
|||
});
|
||||
}
|
||||
|
||||
if has_tstring {
|
||||
let mut parts = Vec::with_capacity(strings.len());
|
||||
for string in strings {
|
||||
match string {
|
||||
StringType::TString(tstring) => parts.push(ast::TStringPart::TString(tstring)),
|
||||
StringType::FString(fstring) => {
|
||||
parts.push(ruff_python_ast::TStringPart::FString(fstring));
|
||||
}
|
||||
StringType::Str(string) => parts.push(ast::TStringPart::Literal(string)),
|
||||
StringType::Bytes(bytes) => parts.push(ast::TStringPart::Literal(
|
||||
ast::StringLiteral::invalid(bytes.range()),
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
return Expr::from(ast::ExprTString {
|
||||
value: ast::TStringValue::concatenated(parts),
|
||||
range,
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
});
|
||||
}
|
||||
|
||||
let mut parts = Vec::with_capacity(strings.len());
|
||||
for string in strings {
|
||||
match string {
|
||||
StringType::FString(fstring) => parts.push(ast::FStringPart::FString(fstring)),
|
||||
StringType::TString(_) => {
|
||||
unreachable!("expected no tstring parts by this point")
|
||||
}
|
||||
StringType::Str(string) => parts.push(ast::FStringPart::Literal(string)),
|
||||
// Bytes and Template strings are invalid at this point
|
||||
// and stored as invalid string literal parts in the
|
||||
// f-string
|
||||
StringType::TString(tstring) => parts.push(ast::FStringPart::Literal(
|
||||
ast::StringLiteral::invalid(tstring.range()),
|
||||
)),
|
||||
StringType::Bytes(bytes) => parts.push(ast::FStringPart::Literal(
|
||||
ast::StringLiteral::invalid(bytes.range()),
|
||||
)),
|
||||
|
|
|
@ -13,7 +13,6 @@ expression: suite
|
|||
range: 0..3,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..3,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -25,7 +24,6 @@ expression: suite
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
[
|
||||
Expr(
|
||||
StmtExpr {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..18,
|
||||
value: TString(
|
||||
ExprTString {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..18,
|
||||
value: TStringValue {
|
||||
inner: Concatenated(
|
||||
[
|
||||
FString(
|
||||
FString {
|
||||
range: 0..9,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 2..8,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "Hello ",
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: FStringFlags {
|
||||
quote_style: Single,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
TString(
|
||||
TString {
|
||||
range: 10..18,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 12..17,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "world",
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Single,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
]
|
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
ParseError {
|
||||
error: OtherError(
|
||||
"cannot mix t-string literals with string or bytes literals",
|
||||
),
|
||||
location: 0..18,
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
[
|
||||
Expr(
|
||||
StmtExpr {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..22,
|
||||
value: TString(
|
||||
ExprTString {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..22,
|
||||
value: TStringValue {
|
||||
inner: Concatenated(
|
||||
[
|
||||
FString(
|
||||
FString {
|
||||
range: 0..9,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 2..8,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "Hello ",
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: FStringFlags {
|
||||
quote_style: Single,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
TString(
|
||||
TString {
|
||||
range: 10..18,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 12..17,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "world",
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Single,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
Literal(
|
||||
StringLiteral {
|
||||
range: 19..22,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "!",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Single,
|
||||
prefix: Empty,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
]
|
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
ParseError {
|
||||
error: OtherError(
|
||||
"cannot mix t-string literals with string or bytes literals",
|
||||
),
|
||||
location: 0..22,
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
[
|
||||
Expr(
|
||||
StmtExpr {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..17,
|
||||
value: TString(
|
||||
ExprTString {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..17,
|
||||
value: TStringValue {
|
||||
inner: Concatenated(
|
||||
[
|
||||
Literal(
|
||||
StringLiteral {
|
||||
range: 0..8,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "Hello ",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Single,
|
||||
prefix: Empty,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
TString(
|
||||
TString {
|
||||
range: 9..17,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 11..16,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "world",
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Single,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
]
|
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
ParseError {
|
||||
error: OtherError(
|
||||
"cannot mix t-string literals with string or bytes literals",
|
||||
),
|
||||
location: 0..17,
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
[
|
||||
Expr(
|
||||
StmtExpr {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..17,
|
||||
value: TString(
|
||||
ExprTString {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..17,
|
||||
value: TStringValue {
|
||||
inner: Concatenated(
|
||||
[
|
||||
Literal(
|
||||
StringLiteral {
|
||||
range: 0..8,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "Hello ",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Single,
|
||||
prefix: Empty,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
TString(
|
||||
TString {
|
||||
range: 9..17,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 11..16,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "world",
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Single,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
]
|
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
ParseError {
|
||||
error: OtherError(
|
||||
"cannot mix t-string literals with string or bytes literals",
|
||||
),
|
||||
location: 0..17,
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
[
|
||||
Expr(
|
||||
StmtExpr {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..22,
|
||||
value: TString(
|
||||
ExprTString {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..22,
|
||||
value: TStringValue {
|
||||
inner: Concatenated(
|
||||
[
|
||||
Literal(
|
||||
StringLiteral {
|
||||
range: 0..8,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "Hello ",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Single,
|
||||
prefix: Empty,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
TString(
|
||||
TString {
|
||||
range: 9..22,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 11..16,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "world",
|
||||
},
|
||||
),
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 16..21,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: StringLiteral(
|
||||
ExprStringLiteral {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 17..20,
|
||||
value: StringLiteralValue {
|
||||
inner: Single(
|
||||
StringLiteral {
|
||||
range: 17..20,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "!",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Double,
|
||||
prefix: Empty,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Single,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
]
|
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
ParseError {
|
||||
error: OtherError(
|
||||
"cannot mix t-string literals with string or bytes literals",
|
||||
),
|
||||
location: 0..22,
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
[
|
||||
Expr(
|
||||
StmtExpr {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..31,
|
||||
value: TString(
|
||||
ExprTString {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..31,
|
||||
value: TStringValue {
|
||||
inner: Concatenated(
|
||||
[
|
||||
Literal(
|
||||
StringLiteral {
|
||||
range: 0..8,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "Hello ",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Single,
|
||||
prefix: Empty,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
TString(
|
||||
TString {
|
||||
range: 9..22,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 11..16,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "world",
|
||||
},
|
||||
),
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 16..21,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: StringLiteral(
|
||||
ExprStringLiteral {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 17..20,
|
||||
value: StringLiteralValue {
|
||||
inner: Single(
|
||||
StringLiteral {
|
||||
range: 17..20,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "!",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Double,
|
||||
prefix: Empty,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Single,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
Literal(
|
||||
StringLiteral {
|
||||
range: 23..31,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "again!",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Single,
|
||||
prefix: Empty,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
]
|
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
ParseError {
|
||||
error: OtherError(
|
||||
"cannot mix t-string literals with string or bytes literals",
|
||||
),
|
||||
location: 0..31,
|
||||
}
|
|
@ -13,7 +13,6 @@ expression: suite
|
|||
range: 0..18,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..18,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -67,7 +66,6 @@ expression: suite
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
|
|
@ -13,7 +13,6 @@ expression: suite
|
|||
range: 0..13,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..13,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -64,7 +63,6 @@ expression: suite
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
|
|
@ -13,7 +13,6 @@ expression: suite
|
|||
range: 0..16,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..16,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -94,7 +93,6 @@ expression: suite
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
|
|
@ -13,7 +13,6 @@ expression: suite
|
|||
range: 0..15,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..15,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -67,7 +66,6 @@ expression: suite
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
|
|
@ -13,7 +13,6 @@ expression: suite
|
|||
range: 0..13,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..13,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -79,7 +78,6 @@ expression: suite
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
|
|
@ -13,7 +13,6 @@ expression: suite
|
|||
range: 0..11,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..11,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -64,7 +63,6 @@ expression: suite
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
|
|
@ -13,7 +13,6 @@ expression: suite
|
|||
range: 0..13,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..13,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -57,7 +56,6 @@ expression: suite
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
|
|
@ -13,7 +13,6 @@ expression: suite
|
|||
range: 0..10,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..10,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -48,7 +47,6 @@ expression: suite
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
|
|
@ -13,7 +13,6 @@ expression: suite
|
|||
range: 0..10,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..10,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -48,7 +47,6 @@ expression: suite
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
|
|
@ -13,7 +13,6 @@ expression: suite
|
|||
range: 0..10,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..10,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -42,7 +41,6 @@ expression: suite
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
[
|
||||
Expr(
|
||||
StmtExpr {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..18,
|
||||
value: TString(
|
||||
ExprTString {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..18,
|
||||
value: TStringValue {
|
||||
inner: Concatenated(
|
||||
[
|
||||
Literal(
|
||||
StringLiteral {
|
||||
range: 0..9,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "Hello ",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Single,
|
||||
prefix: Unicode,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
TString(
|
||||
TString {
|
||||
range: 10..18,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 12..17,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "world",
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Single,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
]
|
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
ParseError {
|
||||
error: OtherError(
|
||||
"cannot mix t-string literals with string or bytes literals",
|
||||
),
|
||||
location: 0..18,
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
[
|
||||
Expr(
|
||||
StmtExpr {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..22,
|
||||
value: TString(
|
||||
ExprTString {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..22,
|
||||
value: TStringValue {
|
||||
inner: Concatenated(
|
||||
[
|
||||
Literal(
|
||||
StringLiteral {
|
||||
range: 0..9,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "Hello ",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Single,
|
||||
prefix: Unicode,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
TString(
|
||||
TString {
|
||||
range: 10..18,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 12..17,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "world",
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Single,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
Literal(
|
||||
StringLiteral {
|
||||
range: 19..22,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "!",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Single,
|
||||
prefix: Empty,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
]
|
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
ParseError {
|
||||
error: OtherError(
|
||||
"cannot mix t-string literals with string or bytes literals",
|
||||
),
|
||||
location: 0..22,
|
||||
}
|
|
@ -13,7 +13,6 @@ expression: suite
|
|||
range: 0..7,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..7,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -45,7 +44,6 @@ expression: suite
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
|
|
@ -13,7 +13,6 @@ expression: suite
|
|||
range: 0..11,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..11,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -45,7 +44,6 @@ expression: suite
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
|
|
@ -13,7 +13,6 @@ expression: suite
|
|||
range: 0..22,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..22,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -81,7 +80,6 @@ expression: suite
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
|
|
@ -13,7 +13,6 @@ expression: suite
|
|||
range: 0..8,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..8,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -50,7 +49,6 @@ expression: suite
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
|
|
@ -13,7 +13,6 @@ expression: suite
|
|||
range: 0..8,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..8,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -50,7 +49,6 @@ expression: suite
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
|
|
@ -13,7 +13,6 @@ expression: suite
|
|||
range: 0..9,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..9,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -52,7 +51,6 @@ expression: suite
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
|
|
@ -13,7 +13,6 @@ expression: suite
|
|||
range: 0..10,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..10,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -48,7 +47,6 @@ expression: suite
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
|
|
@ -13,7 +13,6 @@ expression: suite
|
|||
range: 0..38,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..38,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -84,7 +83,6 @@ expression: suite
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
|
|
@ -13,7 +13,6 @@ expression: suite
|
|||
range: 0..14,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..14,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -62,7 +61,6 @@ expression: suite
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
|
|
@ -13,7 +13,6 @@ expression: suite
|
|||
range: 0..11,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..11,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -50,7 +49,6 @@ expression: suite
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
|
|
@ -850,58 +850,58 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_t_string_concat_1() {
|
||||
fn test_parse_t_string_concat_1_error() {
|
||||
let source = "'Hello ' t'world'";
|
||||
let suite = parse_suite(source).unwrap();
|
||||
let suite = parse_suite(source).unwrap_err();
|
||||
insta::assert_debug_snapshot!(suite);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_t_string_concat_2() {
|
||||
fn test_parse_t_string_concat_2_error() {
|
||||
let source = "'Hello ' t'world'";
|
||||
let suite = parse_suite(source).unwrap();
|
||||
let suite = parse_suite(source).unwrap_err();
|
||||
insta::assert_debug_snapshot!(suite);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_t_string_concat_3() {
|
||||
fn test_parse_t_string_concat_3_error() {
|
||||
let source = "'Hello ' t'world{\"!\"}'";
|
||||
let suite = parse_suite(source).unwrap();
|
||||
let suite = parse_suite(source).unwrap_err();
|
||||
insta::assert_debug_snapshot!(suite);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_t_string_concat_4() {
|
||||
fn test_parse_t_string_concat_4_error() {
|
||||
let source = "'Hello ' t'world{\"!\"}' 'again!'";
|
||||
let suite = parse_suite(source).unwrap();
|
||||
let suite = parse_suite(source).unwrap_err();
|
||||
insta::assert_debug_snapshot!(suite);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_u_t_string_concat_1() {
|
||||
fn test_parse_u_t_string_concat_1_error() {
|
||||
let source = "u'Hello ' t'world'";
|
||||
let suite = parse_suite(source).unwrap();
|
||||
let suite = parse_suite(source).unwrap_err();
|
||||
insta::assert_debug_snapshot!(suite);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_u_t_string_concat_2() {
|
||||
fn test_parse_u_t_string_concat_2_error() {
|
||||
let source = "u'Hello ' t'world' '!'";
|
||||
let suite = parse_suite(source).unwrap();
|
||||
let suite = parse_suite(source).unwrap_err();
|
||||
insta::assert_debug_snapshot!(suite);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_f_t_string_concat_1() {
|
||||
fn test_parse_f_t_string_concat_1_error() {
|
||||
let source = "f'Hello ' t'world'";
|
||||
let suite = parse_suite(source).unwrap();
|
||||
let suite = parse_suite(source).unwrap_err();
|
||||
insta::assert_debug_snapshot!(suite);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_f_t_string_concat_2() {
|
||||
fn test_parse_f_t_string_concat_2_error() {
|
||||
let source = "f'Hello ' t'world' '!'";
|
||||
let suite = parse_suite(source).unwrap();
|
||||
let suite = parse_suite(source).unwrap_err();
|
||||
insta::assert_debug_snapshot!(suite);
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,6 @@ Module(
|
|||
range: 10..19,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 10..19,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -96,7 +95,6 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
|
|
@ -20,7 +20,6 @@ Module(
|
|||
range: 44..49,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 44..49,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -50,7 +49,6 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
@ -66,7 +64,6 @@ Module(
|
|||
range: 50..57,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 50..57,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -96,7 +93,6 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
|
|
@ -20,7 +20,6 @@ Module(
|
|||
range: 44..52,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 44..52,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -50,7 +49,6 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
|
|
@ -20,7 +20,6 @@ Module(
|
|||
range: 44..54,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 44..54,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -50,7 +49,6 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
@ -66,7 +64,6 @@ Module(
|
|||
range: 55..65,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 55..65,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -96,7 +93,6 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
|
|
@ -20,7 +20,6 @@ Module(
|
|||
range: 121..127,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 121..127,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -57,7 +56,6 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
@ -73,7 +71,6 @@ Module(
|
|||
range: 128..141,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 128..141,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -127,7 +124,6 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
@ -143,7 +139,6 @@ Module(
|
|||
range: 142..155,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 142..155,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -188,7 +183,6 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
|
|
@ -20,7 +20,6 @@ Module(
|
|||
range: 44..60,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 44..60,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -92,7 +91,6 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
|
|
@ -20,7 +20,6 @@ Module(
|
|||
range: 44..48,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 44..48,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -50,7 +49,6 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
@ -66,7 +64,6 @@ Module(
|
|||
range: 49..58,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 49..58,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -96,7 +93,6 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
@ -112,7 +108,6 @@ Module(
|
|||
range: 59..67,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 59..67,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -147,7 +142,6 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
@ -164,7 +158,6 @@ Module(
|
|||
value: TStringValue {
|
||||
inner: Concatenated(
|
||||
[
|
||||
TString(
|
||||
TString {
|
||||
range: 68..72,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -193,8 +186,6 @@ Module(
|
|||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
TString(
|
||||
TString {
|
||||
range: 73..81,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -223,7 +214,6 @@ Module(
|
|||
triple_quoted: true,
|
||||
},
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
},
|
||||
|
|
|
@ -20,7 +20,6 @@ Module(
|
|||
range: 44..56,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 44..56,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -63,7 +62,6 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
@ -79,7 +77,6 @@ Module(
|
|||
range: 57..72,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 57..72,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -130,7 +127,6 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
|
|
@ -8,7 +8,7 @@ input_file: crates/ruff_python_parser/resources/inline/err/template_strings_py31
|
|||
Module(
|
||||
ModModule {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..117,
|
||||
range: 0..89,
|
||||
body: [
|
||||
Expr(
|
||||
StmtExpr {
|
||||
|
@ -20,7 +20,6 @@ Module(
|
|||
range: 44..52,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 44..52,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -50,7 +49,6 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
@ -66,7 +64,6 @@ Module(
|
|||
range: 53..63,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 53..63,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -96,7 +93,6 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
@ -112,7 +108,6 @@ Module(
|
|||
range: 64..88,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 64..88,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -132,57 +127,6 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
Expr(
|
||||
StmtExpr {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 89..116,
|
||||
value: TString(
|
||||
ExprTString {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 89..116,
|
||||
value: TStringValue {
|
||||
inner: Concatenated(
|
||||
[
|
||||
Literal(
|
||||
StringLiteral {
|
||||
range: 89..101,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "implicitly",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Double,
|
||||
prefix: Empty,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
TString(
|
||||
TString {
|
||||
range: 101..116,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 103..115,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "concatenated",
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
@ -219,13 +163,4 @@ Module(
|
|||
4 | / t"""what's
|
||||
5 | | happening?"""
|
||||
| |_____________^ Syntax Error: Cannot use t-strings on Python 3.13 (syntax was added in Python 3.14)
|
||||
6 | "implicitly"t"concatenated"
|
||||
|
|
||||
|
||||
|
||||
|
|
||||
4 | t"""what's
|
||||
5 | happening?"""
|
||||
6 | "implicitly"t"concatenated"
|
||||
| ^^^^^^^^^^^^^^^ Syntax Error: Cannot use t-strings on Python 3.13 (syntax was added in Python 3.14)
|
||||
|
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -20,7 +20,6 @@ Module(
|
|||
range: 44..74,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 44..74,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -84,7 +83,6 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
@ -100,7 +98,6 @@ Module(
|
|||
range: 95..112,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 95..112,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -175,7 +172,6 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
@ -191,7 +187,6 @@ Module(
|
|||
range: 148..220,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 148..220,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -255,7 +250,6 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
@ -271,7 +265,6 @@ Module(
|
|||
range: 221..254,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 221..254,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -286,7 +279,6 @@ Module(
|
|||
range: 224..252,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 224..252,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -301,7 +293,6 @@ Module(
|
|||
range: 227..250,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 227..250,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -316,7 +307,6 @@ Module(
|
|||
range: 230..248,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 230..248,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -331,7 +321,6 @@ Module(
|
|||
range: 233..246,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 233..246,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -346,7 +335,6 @@ Module(
|
|||
range: 236..244,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 236..244,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -393,6 +381,21 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -410,6 +413,21 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -427,7 +445,6 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
@ -444,41 +461,6 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
@ -494,7 +476,6 @@ Module(
|
|||
range: 276..310,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 276..310,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -509,7 +490,6 @@ Module(
|
|||
range: 279..302,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 279..302,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -558,7 +538,6 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
@ -582,7 +561,6 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
@ -598,7 +576,6 @@ Module(
|
|||
range: 336..359,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 336..359,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -642,7 +619,6 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
|
|
@ -8,7 +8,7 @@ input_file: crates/ruff_python_parser/resources/inline/ok/template_strings_py314
|
|||
Module(
|
||||
ModModule {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..117,
|
||||
range: 0..89,
|
||||
body: [
|
||||
Expr(
|
||||
StmtExpr {
|
||||
|
@ -20,7 +20,6 @@ Module(
|
|||
range: 44..52,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 44..52,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -50,7 +49,6 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
@ -66,7 +64,6 @@ Module(
|
|||
range: 53..63,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 53..63,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -96,7 +93,6 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
@ -112,7 +108,6 @@ Module(
|
|||
range: 64..88,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 64..88,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
|
@ -132,57 +127,6 @@ Module(
|
|||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
Expr(
|
||||
StmtExpr {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 89..116,
|
||||
value: TString(
|
||||
ExprTString {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 89..116,
|
||||
value: TStringValue {
|
||||
inner: Concatenated(
|
||||
[
|
||||
Literal(
|
||||
StringLiteral {
|
||||
range: 89..101,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "implicitly",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Double,
|
||||
prefix: Empty,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
TString(
|
||||
TString {
|
||||
range: 101..116,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 103..115,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "concatenated",
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
|
|
|
@ -5424,31 +5424,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
|
|||
|
||||
fn infer_tstring_expression(&mut self, tstring: &ast::ExprTString) -> Type<'db> {
|
||||
let ast::ExprTString { value, .. } = tstring;
|
||||
for part in value {
|
||||
match part {
|
||||
ast::TStringPart::Literal(_) => {}
|
||||
ast::TStringPart::FString(fstring) => {
|
||||
for element in &fstring.elements {
|
||||
match element {
|
||||
ast::InterpolatedStringElement::Interpolation(expression) => {
|
||||
let ast::InterpolatedElement {
|
||||
expression,
|
||||
format_spec,
|
||||
..
|
||||
} = expression;
|
||||
self.infer_expression(expression);
|
||||
|
||||
if let Some(format_spec) = format_spec {
|
||||
for element in format_spec.elements.interpolations() {
|
||||
self.infer_expression(&element.expression);
|
||||
}
|
||||
}
|
||||
}
|
||||
ast::InterpolatedStringElement::Literal(_) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
ast::TStringPart::TString(tstring) => {
|
||||
for tstring in value {
|
||||
for element in &tstring.elements {
|
||||
match element {
|
||||
ast::InterpolatedStringElement::Interpolation(
|
||||
|
@ -5470,8 +5446,6 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
todo_type!("Template")
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue