Apply Python name mangling for private attributes. `__x` becomes `_ClassName__x` if inside a class.
(class_name: &str, name: &str)
| 2922 | /// Apply Python name mangling for private attributes. |
| 2923 | /// `__x` becomes `_ClassName__x` if inside a class. |
| 2924 | fn 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)] |
| 2935 | mod tests { |
no test coverage detected