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

Method __add__

crates/vm/src/builtins/str.rs:591–609  ·  view source on GitHub ↗
(zelf: PyRef<Self>, other: PyObjectRef, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

589)]
590impl PyStr {
591 fn __add__(zelf: PyRef<Self>, other: PyObjectRef, vm: &VirtualMachine) -> PyResult {
592 if let Some(other) = other.downcast_ref::<Self>() {
593 let bytes = zelf.as_wtf8().py_add(other.as_wtf8());
594 Ok(unsafe {
595 // SAFETY: `kind` is safely decided
596 let kind = zelf.kind() | other.kind();
597 Self::new_str_unchecked(bytes.into(), kind)
598 }
599 .to_pyobject(vm))
600 } else if let Some(radd) = vm.get_method(other.clone(), identifier!(vm, __radd__)) {
601 // hack to get around not distinguishing number add from seq concat
602 radd?.call((zelf,), vm)
603 } else {
604 Err(vm.new_type_error(format!(
605 r#"can only concatenate str (not "{}") to str"#,
606 other.class().name()
607 )))
608 }
609 }
610
611 fn _contains(&self, needle: &PyObject, vm: &VirtualMachine) -> PyResult<bool> {
612 if let Some(needle) = needle.downcast_ref::<Self>() {

Callers

nothing calls this directly

Calls 8

py_addMethod · 0.80
ErrClass · 0.50
as_wtf8Method · 0.45
to_pyobjectMethod · 0.45
kindMethod · 0.45
get_methodMethod · 0.45
cloneMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected