Add pyo3 support:

This commit is contained in:
Jeong YunWon 2023-05-20 15:45:54 +09:00
parent 6b90a006a1
commit 4119a9084b
4 changed files with 5 additions and 3 deletions

View file

@ -30,6 +30,7 @@ itertools = "0.10.3"
is-macro = "0.2.2"
log = "0.4.16"
num-complex = "0.4.0"
num-bigint = "0.4.3"
num-traits = "0.2"
pyo3 = { version = "0.18.3" }
malachite-bigint = { version = "0.1.5", git = "https://github.com/qingshi163/malachite-bigint.git" }

View file

@ -15,7 +15,7 @@ fold = []
unparse = ["rustpython-literal"]
visitor = []
all-nodes-with-ranges = []
pyo3 = ["dep:pyo3", "num-complex", "once_cell"]
pyo3 = ["dep:pyo3", "num-complex", "once_cell", "num-bigint", "malachite-bigint/num-bigint"]
# This feature is experimental
# It reimplements AST types, but currently both slower than python AST types and limited to use in other API
@ -26,6 +26,7 @@ rustpython-parser-core = { workspace = true }
rustpython-literal = { workspace = true, optional = true }
is-macro = { workspace = true }
num-bigint = { workspace = true, optional = true }
static_assertions = "1.1.0"
num-complex = { workspace = true, optional = true }
once_cell = { workspace = true, optional = true }

View file

@ -90,7 +90,7 @@ impl ToPyo3Ast for crate::Constant {
crate::Constant::Bool(bool) => bool.to_object(py),
crate::Constant::Str(string) => string.to_object(py),
crate::Constant::Bytes(bytes) => PyBytes::new(py, bytes).into(),
crate::Constant::Int(int) => int.to_object(py),
crate::Constant::Int(int) => num_bigint::BigInt::from(int.clone()).to_object(py),
crate::Constant::Tuple(elts) => {
let elts: PyResult<Vec<_>> = elts.iter().map(|c| c.to_pyo3_ast(py)).collect();
PyTuple::new(py, elts?).into()

View file

@ -67,7 +67,7 @@ impl ToPyo3Wrapper for crate::Constant {
crate::Constant::Bool(bool) => bool.to_object(py),
crate::Constant::Str(string) => string.to_object(py),
crate::Constant::Bytes(bytes) => PyBytes::new(py, bytes).into(),
crate::Constant::Int(int) => int.to_object(py),
crate::Constant::Int(int) => num_bigint::BigInt::from(int.clone()).to_object(py),
crate::Constant::Tuple(elts) => {
let elts: PyResult<Vec<_>> = elts.iter().map(|c| c.to_pyo3_wrapper(py)).collect();
PyTuple::new(py, elts?).into()