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

Avoid off-by-one error in with-item named expressions #8915

Merged
merged 1 commit into from
Nov 30, 2023
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
2 changes: 1 addition & 1 deletion crates/ruff_python_parser/src/python.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ WithItems: Vec<ast::WithItem> = {
// ```
// In this case, the `(` and `)` are part of the `with` statement.
// The same applies to `yield` and `yield from`.
let item = if matches!(item.context_expr, ast::Expr::NamedExpr(_) | ast::Expr::Yield(_) | ast::Expr::YieldFrom(_)) {
let item = if item.optional_vars.is_none() && matches!(item.context_expr, ast::Expr::NamedExpr(_) | ast::Expr::Yield(_) | ast::Expr::YieldFrom(_)) {
ast::WithItem {
range: item.range().add_start(TextSize::new(1)).sub_end(TextSize::new(1)),
context_expr: item.context_expr,
Expand Down
4 changes: 2 additions & 2 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: e999c9c9ca8fe5a29655244aa995b8cf4e639f0bda95099d8f2a395bc06b6408
// sha3: c7c0b9368fa05f7d2fc1d06a665ff4232555f276a1d9569afdbc86d0905b3a2a
use ruff_text_size::{Ranged, TextLen, TextRange, TextSize};
use ruff_python_ast::{self as ast, Int, IpyEscapeKind};
use crate::{
Expand Down Expand Up @@ -35374,7 +35374,7 @@ fn __action159<
// ```
// In this case, the `(` and `)` are part of the `with` statement.
// The same applies to `yield` and `yield from`.
let item = if matches!(item.context_expr, ast::Expr::NamedExpr(_) | ast::Expr::Yield(_) | ast::Expr::YieldFrom(_)) {
let item = if item.optional_vars.is_none() && matches!(item.context_expr, ast::Expr::NamedExpr(_) | ast::Expr::Yield(_) | ast::Expr::YieldFrom(_)) {
ast::WithItem {
range: item.range().add_start(TextSize::new(1)).sub_end(TextSize::new(1)),
context_expr: item.context_expr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ expression: "parse_suite(source, \"<test>\").unwrap()"
is_async: false,
items: [
WithItem {
range: 184..195,
range: 183..196,
context_expr: NamedExpr(
ExprNamedExpr {
range: 184..190,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ expression: "parse_suite(source, \"<test>\").unwrap()"
is_async: false,
items: [
WithItem {
range: 382..393,
range: 381..394,
context_expr: NamedExpr(
ExprNamedExpr {
range: 382..388,
Expand Down