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

Method basename

crates/vm/src/exceptions.rs:2329–2341  ·  view source on GitHub ↗
(filename: &Wtf8)

Source from the content-addressed store, hash-verified

2327 #[pymethod]
2328 fn __str__(zelf: &Py<PyBaseException>, vm: &VirtualMachine) -> PyResult<PyStrRef> {
2329 fn basename(filename: &Wtf8) -> &Wtf8 {
2330 let bytes = filename.as_bytes();
2331 let pos = if cfg!(windows) {
2332 bytes.iter().rposition(|&b| b == b'/' || b == b'\\')
2333 } else {
2334 bytes.iter().rposition(|&b| b == b'/')
2335 };
2336 match pos {
2337 // SAFETY: splitting at ASCII byte boundary preserves WTF-8 validity
2338 Some(pos) => unsafe { Wtf8::from_bytes_unchecked(&bytes[pos + 1..]) },
2339 None => filename,
2340 }
2341 }
2342
2343 let maybe_lineno = zelf
2344 .as_object()

Callers 15

webpack.config.jsFile · 0.80
_synthesizeFunction · 0.80
__init__Method · 0.80
getmodulenameFunction · 0.80
compile_fileFunction · 0.80
importfileFunction · 0.80
cliFunction · 0.80
copyFunction · 0.80
copy2Function · 0.80
_basenameFunction · 0.80
testfileFunction · 0.80

Calls 2

as_bytesMethod · 0.45
iterMethod · 0.45

Tested by 15

testfileFunction · 0.64
DocFileTestFunction · 0.64
test_scriptMethod · 0.64
info_breakpointsFunction · 0.64
test_cwdMethod · 0.64
check_traceback_entryMethod · 0.64
_test_exceptionMethod · 0.64
test_basenameMethod · 0.64
test_promptMethod · 0.64
test_synthesizeMethod · 0.64
test_script_abspathMethod · 0.64