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

Method as_number

crates/vm/src/builtins/str.rs:1595–1621  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1593
1594impl AsNumber for PyStr {
1595 fn as_number() -> &'static PyNumberMethods {
1596 static AS_NUMBER: PyNumberMethods = PyNumberMethods {
1597 add: Some(|a, b, vm| {
1598 let Some(a) = a.downcast_ref::<PyStr>() else {
1599 return Ok(vm.ctx.not_implemented());
1600 };
1601 let Some(b) = b.downcast_ref::<PyStr>() else {
1602 return Ok(vm.ctx.not_implemented());
1603 };
1604 let bytes = a.as_wtf8().py_add(b.as_wtf8());
1605 Ok(unsafe {
1606 let kind = a.kind() | b.kind();
1607 PyStr::new_str_unchecked(bytes.into(), kind)
1608 }
1609 .to_pyobject(vm))
1610 }),
1611 remainder: Some(|a, b, vm| {
1612 if let Some(a) = a.downcast_ref::<PyStr>() {
1613 a.__mod__(b.to_owned(), vm).to_pyresult(vm)
1614 } else {
1615 Ok(vm.ctx.not_implemented())
1616 }
1617 }),
1618 ..PyNumberMethods::NOT_IMPLEMENTED
1619 };
1620 &AS_NUMBER
1621 }
1622}
1623
1624impl AsSequence for PyStr {

Callers

nothing calls this directly

Calls 9

py_addMethod · 0.80
SomeClass · 0.50
not_implementedMethod · 0.45
as_wtf8Method · 0.45
to_pyobjectMethod · 0.45
kindMethod · 0.45
to_pyresultMethod · 0.45
__mod__Method · 0.45
to_ownedMethod · 0.45

Tested by

no test coverage detected