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

Function raise_indentation_error

crates/stdlib/src/_tokenize.rs:475–496  ·  view source on GitHub ↗

Raise an IndentationError from a parse error.

(
        vm: &VirtualMachine,
        err: &ParseError,
        source: &str,
        line_index: &LineIndex,
    )

Source from the content-addressed store, hash-verified

473
474 /// Raise an IndentationError from a parse error.
475 fn raise_indentation_error(
476 vm: &VirtualMachine,
477 err: &ParseError,
478 source: &str,
479 line_index: &LineIndex,
480 ) -> rustpython_vm::builtins::PyBaseExceptionRef {
481 let err_lc = line_index.line_column(err.location.start(), source);
482 let err_line_text = source.full_line_str(err.location.start());
483 let err_text = err_line_text.trim_end_matches('\n').trim_end_matches('\r');
484 let msg = format!("{}", err.error);
485 let exc = vm.new_exception_msg(
486 vm.ctx.exceptions.indentation_error.to_owned(),
487 msg.clone().into(),
488 );
489 let obj = exc.as_object();
490 let _ = obj.set_attr("lineno", vm.ctx.new_int(err_lc.line.get()), vm);
491 let _ = obj.set_attr("offset", vm.ctx.new_int(err_text.len() as i64 + 1), vm);
492 let _ = obj.set_attr("msg", vm.ctx.new_str(msg), vm);
493 let _ = obj.set_attr("filename", vm.ctx.new_str("<string>"), vm);
494 let _ = obj.set_attr("text", vm.ctx.new_str(err_text), vm);
495 exc
496 }
497
498 /// Split an FSTRING_MIDDLE/TSTRING_MIDDLE token containing `{{`/`}}`
499 /// into multiple unescaped sub-tokens.

Callers 1

emit_next_tokenFunction · 0.85

Calls 11

trim_end_matchesMethod · 0.80
new_exception_msgMethod · 0.80
startMethod · 0.45
to_ownedMethod · 0.45
cloneMethod · 0.45
as_objectMethod · 0.45
set_attrMethod · 0.45
new_intMethod · 0.45
getMethod · 0.45
lenMethod · 0.45
new_strMethod · 0.45

Tested by

no test coverage detected