Skip to content

Commit 5270020

Browse files
authored
rustpython_ast python package (#79)
1 parent edcfcb4 commit 5270020

File tree

5 files changed

+13
-4
lines changed

5 files changed

+13
-4
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ log = "0.4.16"
3333
num-complex = "0.4.0"
3434
num-bigint = "0.4.3"
3535
num-traits = "0.2"
36-
pyo3 = { version = "0.18.3" }
36+
pyo3 = { version = "0.19.0" }
3737
malachite-bigint = { version = "0.1.0" }
3838
memchr = "2.5.0"
3939
rand = "0.8.5"

ast-pyo3/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
[package]
22
name = "rustpython-ast-pyo3"
3-
version = "0.1.0"
3+
version = "0.0.1"
44
edition = "2021"
55

66
[features]
7+
# abi3 = ["pyo3/abi3-py37"] # will be supported from next pyo3 version
78
# This feature is experimental
89
# It reimplements AST types, but currently both slower than python AST types and limited to use in other API
910
wrapper = []
@@ -16,6 +17,7 @@ crate-type = ["cdylib"]
1617
rustpython-ast = { workspace = true, features = ["location"] }
1718
rustpython-parser = { workspace = true, features = ["num-bigint"] }
1819
num-complex = { workspace = true }
20+
num-traits = { workspace = true }
1921
once_cell = { workspace = true }
2022

2123
pyo3 = { workspace = true, features = ["num-bigint", "num-complex"] }

ast-pyo3/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ classifiers = [
1010
"Programming Language :: Python :: Implementation :: CPython",
1111
]
1212

13-
1413
[tool.maturin]
14+
# module-name = "_rustpython_ast"
1515
features = ["pyo3/extension-module"]

ast-pyo3/rustpython_ast/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from rustpython_ast.rustpython_ast import parse
2+
3+
__all__ = ["parse"]

ast-pyo3/src/py_ast.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use num_complex::Complex64;
2+
use num_traits::cast::ToPrimitive;
23
use once_cell::sync::OnceCell;
34
use pyo3::{
45
prelude::*,
@@ -97,7 +98,10 @@ fn constant_to_object(constant: &ast::Constant, py: Python) -> PyObject {
9798
ast::Constant::Bool(bool) => cache.bool(py, *bool).into(),
9899
ast::Constant::Str(string) => string.to_object(py),
99100
ast::Constant::Bytes(bytes) => PyBytes::new(py, bytes).into(),
100-
ast::Constant::Int(int) => int.to_object(py),
101+
ast::Constant::Int(int) => match int.to_i64() {
102+
Some(small_int) => small_int.to_object(py),
103+
None => int.to_object(py),
104+
},
101105
ast::Constant::Tuple(elts) => {
102106
let elts: Vec<_> = elts.iter().map(|c| constant_to_object(c, py)).collect();
103107
PyTuple::new(py, elts).into()

0 commit comments

Comments
 (0)