MCPcopy Index your code
hub / github.com/RustPython/RustPython / new_syntax_error_maybe_incomplete

Method new_syntax_error_maybe_incomplete

crates/vm/src/vm/vm_new.rs:330–682  ·  view source on GitHub ↗
(
        &self,
        error: &crate::compiler::CompileError,
        source: Option<&str>,
        allow_incomplete: bool,
    )

Source from the content-addressed store, hash-verified

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 ..

Callers 2

to_pyexceptionMethod · 0.80
new_syntax_errorMethod · 0.80

Calls 15

collectMethod · 0.80
charsMethod · 0.80
starts_withMethod · 0.80
to_stringMethod · 0.80
get_mutMethod · 0.80
make_ascii_lowercaseMethod · 0.80
eq_ignore_ascii_caseMethod · 0.80
isMethod · 0.80
new_exception_msgMethod · 0.80
python_locationMethod · 0.80
python_end_locationMethod · 0.80
SomeClass · 0.50

Tested by

no test coverage detected