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

Function print_source_line

crates/vm/src/exceptions.rs:369–393  ·  view source on GitHub ↗
(
    output: &mut W,
    filename: &str,
    lineno: usize,
)

Source from the content-addressed store, hash-verified

367}
368
369fn print_source_line<W: Write>(
370 output: &mut W,
371 filename: &str,
372 lineno: usize,
373) -> Result<(), W::Error> {
374 // TODO: use io.open() method instead, when available, according to https://github.com/python/cpython/blob/main/Python/traceback.c#L393
375 // TODO: support different encodings
376 let file = match std::fs::File::open(filename) {
377 Ok(file) => file,
378 Err(_) => return Ok(()),
379 };
380 let file = BufReader::new(file);
381
382 for (i, line) in file.lines().enumerate() {
383 if i + 1 == lineno {
384 if let Ok(line) = line {
385 // Indented with 4 spaces
386 writeln!(output, " {}", line.trim_start())?;
387 }
388 return Ok(());
389 }
390 }
391
392 Ok(())
393}
394
395/// Print exception occurrence location from traceback element
396fn write_traceback_entry<W: Write>(

Callers 1

write_traceback_entryFunction · 0.85

Calls 2

newFunction · 0.85
openFunction · 0.50

Tested by

no test coverage detected