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

Method digit

crates/stdlib/src/unicodedata.rs:256–273  ·  view source on GitHub ↗
(
            &self,
            character: PyStrRef,
            default: OptionalArg<PyObjectRef>,
            vm: &VirtualMachine,
        )

Source from the content-addressed store, hash-verified

254
255 #[pymethod]
256 fn digit(
257 &self,
258 character: PyStrRef,
259 default: OptionalArg<PyObjectRef>,
260 vm: &VirtualMachine,
261 ) -> PyResult {
262 let ch = self.extract_char(character, vm)?.and_then(|c| c.to_char());
263 if let Some(ch) = ch
264 && matches!(
265 ch.numeric_type(),
266 Some(NumericType::Decimal) | Some(NumericType::Digit)
267 )
268 && let Some(Number::Integer(n)) = ch.numeric_value()
269 {
270 return Ok(vm.ctx.new_int(n).into());
271 }
272 default.ok_or_else(|| vm.new_value_error("not a digit"))
273 }
274
275 #[pymethod]
276 fn decimal(

Callers 3

test_digitMethod · 0.80

Calls 4

extract_charMethod · 0.80
ok_or_elseMethod · 0.80
to_charMethod · 0.45
new_intMethod · 0.45

Tested by 3

test_digitMethod · 0.64