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

Method ast_from_object

crates/vm/src/stdlib/_ast/other.rs:9–23  ·  view source on GitHub ↗
(
        vm: &VirtualMachine,
        _source_file: &SourceFile,
        object: PyObjectRef,
    )

Source from the content-addressed store, hash-verified

7 }
8
9 fn ast_from_object(
10 vm: &VirtualMachine,
11 _source_file: &SourceFile,
12 object: PyObjectRef,
13 ) -> PyResult<Self> {
14 // Python's AST uses ASCII codes: 's', 'r', 'a', -1=None
15 // Note: 255 is -1i8 as u8 (ruff's ConversionFlag::None)
16 match i32::try_from_object(vm, object)? {
17 -1 | 255 => Ok(Self::None),
18 x if x == b's' as i32 => Ok(Self::Str),
19 x if x == b'r' as i32 => Ok(Self::Repr),
20 x if x == b'a' as i32 => Ok(Self::Ascii),
21 _ => Err(vm.new_value_error("invalid conversion flag")),
22 }
23 }
24}
25
26// /// This is just a string, not strictly an AST node. But it makes AST conversions easier.

Callers

nothing calls this directly

Calls 7

newFunction · 0.85
ast_from_objectFunction · 0.85
get_node_fieldFunction · 0.85
get_node_field_optFunction · 0.85
range_from_objectFunction · 0.85
ErrClass · 0.50
mapMethod · 0.45

Tested by

no test coverage detected