From 2b82caa163989a236110f77ea8ab9f860b7c49a2 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Mon, 19 Jun 2023 00:09:02 -0400 Subject: [PATCH] Detect continuations at start-of-file (#5173) ## Summary Given: ```python \ import os ``` Deleting `import os` leaves a syntax error: a file can't end in a continuation. We have code to handle this case, but it failed to pick up continuations at the _very start_ of a file. Closes #5156. --- crates/ruff_python_ast/src/source_code/indexer.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/crates/ruff_python_ast/src/source_code/indexer.rs b/crates/ruff_python_ast/src/source_code/indexer.rs index 6cfdf693ca..3d10678a50 100644 --- a/crates/ruff_python_ast/src/source_code/indexer.rs +++ b/crates/ruff_python_ast/src/source_code/indexer.rs @@ -49,10 +49,7 @@ impl Indexer { } // Newlines after a newline never form a continuation. - if !matches!( - prev_token, - Some(Tok::Newline | Tok::NonLogicalNewline) | None - ) { + if !matches!(prev_token, Some(Tok::Newline | Tok::NonLogicalNewline)) { continuation_lines.push(line_start); }