(
&self,
error: &crate::compiler::CompileError,
source: Option<&str>,
allow_incomplete: bool,
)
| 328 | |
| 329 | #[cfg(any(feature = "parser", feature = "compiler"))] |
| 330 | pub fn new_syntax_error_maybe_incomplete( |
| 331 | &self, |
| 332 | error: &crate::compiler::CompileError, |
| 333 | source: Option<&str>, |
| 334 | allow_incomplete: bool, |
| 335 | ) -> PyBaseExceptionRef { |
| 336 | let incomplete_or_syntax = |allow| -> &'static Py<crate::builtins::PyType> { |
| 337 | if allow { |
| 338 | self.ctx.exceptions.incomplete_input_error |
| 339 | } else { |
| 340 | self.ctx.exceptions.syntax_error |
| 341 | } |
| 342 | }; |
| 343 | |
| 344 | let syntax_error_type = match &error { |
| 345 | #[cfg(feature = "parser")] |
| 346 | crate::compiler::CompileError::Parse(rustpython_compiler::ParseError { |
| 347 | error: |
| 348 | ruff_python_parser::ParseErrorType::Lexical( |
| 349 | ruff_python_parser::LexicalErrorType::IndentationError, |
| 350 | ), |
| 351 | .. |
| 352 | }) => { |
| 353 | // Detect tab/space mixing to raise TabError instead of IndentationError. |
| 354 | // This checks both within a single line and across different lines. |
| 355 | let is_tab_error = source.is_some_and(|source| { |
| 356 | let mut has_space_indent = false; |
| 357 | let mut has_tab_indent = false; |
| 358 | for line in source.lines() { |
| 359 | let indent: Vec<u8> = line |
| 360 | .bytes() |
| 361 | .take_while(|&b| b == b' ' || b == b'\t') |
| 362 | .collect(); |
| 363 | if indent.is_empty() { |
| 364 | continue; |
| 365 | } |
| 366 | if indent.contains(&b' ') && indent.contains(&b'\t') { |
| 367 | return true; |
| 368 | } |
| 369 | if indent.contains(&b' ') { |
| 370 | has_space_indent = true; |
| 371 | } |
| 372 | if indent.contains(&b'\t') { |
| 373 | has_tab_indent = true; |
| 374 | } |
| 375 | } |
| 376 | has_space_indent && has_tab_indent |
| 377 | }); |
| 378 | if is_tab_error { |
| 379 | self.ctx.exceptions.tab_error |
| 380 | } else { |
| 381 | self.ctx.exceptions.indentation_error |
| 382 | } |
| 383 | } |
| 384 | #[cfg(feature = "parser")] |
| 385 | crate::compiler::CompileError::Parse(rustpython_compiler::ParseError { |
| 386 | error: ruff_python_parser::ParseErrorType::UnexpectedIndentation, |
| 387 | .. |
no test coverage detected