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

Function mangle_name

crates/vm/src/builtins/type.rs:2924–2932  ·  view source on GitHub ↗

Apply Python name mangling for private attributes. `__x` becomes `_ClassName__x` if inside a class.

(class_name: &str, name: &str)

Source from the content-addressed store, hash-verified

2922/// Apply Python name mangling for private attributes.
2923/// `__x` becomes `_ClassName__x` if inside a class.
2924fn mangle_name(class_name: &str, name: &str) -> String {
2925 // Only mangle names starting with __ and not ending with __
2926 if !name.starts_with("__") || name.ends_with("__") || name.contains('.') {
2927 return name.to_string();
2928 }
2929 // Strip leading underscores from class name
2930 let class_name = class_name.trim_start_matches('_');
2931 format!("_{}{}", class_name, name)
2932}
2933
2934#[cfg(test)]
2935mod tests {

Callers 1

slot_newMethod · 0.70

Calls 5

starts_withMethod · 0.80
ends_withMethod · 0.80
to_stringMethod · 0.80
trim_start_matchesMethod · 0.80
containsMethod · 0.45

Tested by

no test coverage detected