Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use non-parenthesized range for DebugText #9953

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/ruff_python_codegen/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1705,6 +1705,7 @@ class Foo:
assert_round_trip!(r#"f"{ chr(65) = !s}""#);
assert_round_trip!(r#"f"{ chr(65) = !r}""#);
assert_round_trip!(r#"f"{ chr(65) = :#x}""#);
assert_round_trip!(r#"f"{ ( chr(65) ) = }""#);
assert_round_trip!(r#"f"{a=!r:0.05f}""#);
}

Expand Down
1 change: 1 addition & 0 deletions crates/ruff_python_parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,7 @@ f"""{
y
z
}"""
f"{ ( foo ) = }"
"#
.trim(),
)
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff_python_parser/src/python.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -1656,8 +1656,8 @@ FStringReplacementField: ast::FStringElement = {
)
};
ast::DebugText {
leading: source_code[TextRange::new(start_offset, value.start())].to_string(),
trailing: source_code[TextRange::new(value.end(), end_offset)].to_string(),
leading: source_code[TextRange::new(start_offset, value.expr.start())].to_string(),
trailing: source_code[TextRange::new(value.expr.end(), end_offset)].to_string(),
}
});
Ok(
Expand Down
6 changes: 3 additions & 3 deletions crates/ruff_python_parser/src/python.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// auto-generated: "lalrpop 0.20.0"
// sha3: d38cc0f2252a58db42d3bd63a102b537865992b3cf51d402cdb4828f48989c9d
// sha3: 8c85e4bbac54760ed8be03b56a428d76e14d18e6dbde62b424d0b2b5e8e65dbe
use ruff_text_size::{Ranged, TextLen, TextRange, TextSize};
use ruff_python_ast::{self as ast, Int, IpyEscapeKind};
use crate::{
Expand Down Expand Up @@ -36457,8 +36457,8 @@ fn __action221<
)
};
ast::DebugText {
leading: source_code[TextRange::new(start_offset, value.start())].to_string(),
trailing: source_code[TextRange::new(value.end(), end_offset)].to_string(),
leading: source_code[TextRange::new(start_offset, value.expr.start())].to_string(),
trailing: source_code[TextRange::new(value.expr.end(), end_offset)].to_string(),
}
});
Ok(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -942,4 +942,45 @@ expression: parse_ast
),
},
),
Expr(
StmtExpr {
range: 374..392,
value: FString(
ExprFString {
range: 374..392,
value: FStringValue {
inner: Single(
FString(
FString {
range: 374..392,
elements: [
Expression(
FStringExpressionElement {
range: 376..391,
expression: Name(
ExprName {
range: 381..384,
id: "foo",
ctx: Load,
},
),
debug_text: Some(
DebugText {
leading: " ( ",
trailing: " ) = ",
},
),
conversion: None,
format_spec: None,
},
),
],
},
),
),
},
},
),
},
),
]
Loading