Skip to content

Commit fdec727

Browse files
authored
New Arguments and Arg/ArgWithDefault AST representation (#59)
1 parent 3fbf4f6 commit fdec727

File tree

51 files changed

+12449
-11512
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+12449
-11512
lines changed

ast-pyo3/src/gen/to_py_ast.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ impl<R> PyNode for ast::ExcepthandlerExceptHandler<R> {
808808
}
809809
}
810810

811-
impl<R> PyNode for ast::Arguments<R> {
811+
impl<R> PyNode for ast::PythonArguments<R> {
812812
#[inline]
813813
fn py_type_cache() -> &'static OnceCell<(Py<PyAny>, Py<PyAny>)> {
814814
static PY_TYPE: OnceCell<(Py<PyAny>, Py<PyAny>)> = OnceCell::new();
@@ -2288,7 +2288,7 @@ impl ToPyAst for ast::ExcepthandlerExceptHandler<TextRange> {
22882288
}
22892289
}
22902290

2291-
impl ToPyAst for ast::Arguments<TextRange> {
2291+
impl ToPyAst for ast::PythonArguments<TextRange> {
22922292
#[inline]
22932293
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
22942294
let cache = Self::py_type_cache().get().unwrap();
@@ -4312,7 +4312,7 @@ impl ToPyAst for ast::ExcepthandlerExceptHandler<SourceRange> {
43124312
}
43134313
}
43144314

4315-
impl ToPyAst for ast::Arguments<SourceRange> {
4315+
impl ToPyAst for ast::PythonArguments<SourceRange> {
43164316
#[inline]
43174317
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
43184318
let cache = Self::py_type_cache().get().unwrap();
@@ -4820,7 +4820,7 @@ fn init_types(py: Python) -> PyResult<()> {
48204820
cache_py_type::<ast::Comprehension>(ast_module)?;
48214821
cache_py_type::<ast::Excepthandler>(ast_module)?;
48224822
cache_py_type::<ast::ExcepthandlerExceptHandler>(ast_module)?;
4823-
cache_py_type::<ast::Arguments>(ast_module)?;
4823+
cache_py_type::<ast::PythonArguments>(ast_module)?;
48244824
cache_py_type::<ast::Arg>(ast_module)?;
48254825
cache_py_type::<ast::Keyword>(ast_module)?;
48264826
cache_py_type::<ast::Alias>(ast_module)?;

ast-pyo3/src/gen/wrapper_located.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3289,10 +3289,10 @@ impl ExcepthandlerExceptHandler {
32893289

32903290
#[pyclass(module="rustpython_ast.located", name="_arguments", extends=super::Ast, frozen)]
32913291
#[derive(Clone, Debug)]
3292-
pub struct Arguments(pub &'static ast::Arguments<SourceRange>);
3292+
pub struct Arguments(pub &'static ast::PythonArguments<SourceRange>);
32933293

3294-
impl From<&'static ast::Arguments<SourceRange>> for Arguments {
3295-
fn from(node: &'static ast::Arguments<SourceRange>) -> Self {
3294+
impl From<&'static ast::PythonArguments<SourceRange>> for Arguments {
3295+
fn from(node: &'static ast::PythonArguments<SourceRange>) -> Self {
32963296
Arguments(node)
32973297
}
32983298
}
@@ -3304,7 +3304,7 @@ impl ToPyObject for Arguments {
33043304
}
33053305
}
33063306

3307-
impl ToPyWrapper for ast::Arguments<SourceRange> {
3307+
impl ToPyWrapper for ast::PythonArguments<SourceRange> {
33083308
#[inline]
33093309
fn to_py_wrapper(&'static self, py: Python) -> PyResult<Py<PyAny>> {
33103310
Ok(Arguments(self).to_object(py))
@@ -4392,7 +4392,7 @@ pub fn add_to_module(py: Python, m: &PyModule) -> PyResult<()> {
43924392
super::init_type::<Comprehension, ast::Comprehension>(py, m)?;
43934393
super::init_type::<Excepthandler, ast::Excepthandler>(py, m)?;
43944394
super::init_type::<ExcepthandlerExceptHandler, ast::ExcepthandlerExceptHandler>(py, m)?;
4395-
super::init_type::<Arguments, ast::Arguments>(py, m)?;
4395+
super::init_type::<Arguments, ast::PythonArguments>(py, m)?;
43964396
super::init_type::<Arg, ast::Arg>(py, m)?;
43974397
super::init_type::<Keyword, ast::Keyword>(py, m)?;
43984398
super::init_type::<Alias, ast::Alias>(py, m)?;

ast-pyo3/src/gen/wrapper_ranged.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3289,10 +3289,10 @@ impl ExcepthandlerExceptHandler {
32893289

32903290
#[pyclass(module="rustpython_ast.ranged", name="_arguments", extends=super::Ast, frozen)]
32913291
#[derive(Clone, Debug)]
3292-
pub struct Arguments(pub &'static ast::Arguments<TextRange>);
3292+
pub struct Arguments(pub &'static ast::PythonArguments<TextRange>);
32933293

3294-
impl From<&'static ast::Arguments<TextRange>> for Arguments {
3295-
fn from(node: &'static ast::Arguments<TextRange>) -> Self {
3294+
impl From<&'static ast::PythonArguments<TextRange>> for Arguments {
3295+
fn from(node: &'static ast::PythonArguments<TextRange>) -> Self {
32963296
Arguments(node)
32973297
}
32983298
}
@@ -3304,7 +3304,7 @@ impl ToPyObject for Arguments {
33043304
}
33053305
}
33063306

3307-
impl ToPyWrapper for ast::Arguments<TextRange> {
3307+
impl ToPyWrapper for ast::PythonArguments<TextRange> {
33083308
#[inline]
33093309
fn to_py_wrapper(&'static self, py: Python) -> PyResult<Py<PyAny>> {
33103310
Ok(Arguments(self).to_object(py))
@@ -4096,7 +4096,7 @@ pub fn add_to_module(py: Python, m: &PyModule) -> PyResult<()> {
40964096
super::init_type::<Comprehension, ast::Comprehension>(py, m)?;
40974097
super::init_type::<Excepthandler, ast::Excepthandler>(py, m)?;
40984098
super::init_type::<ExcepthandlerExceptHandler, ast::ExcepthandlerExceptHandler>(py, m)?;
4099-
super::init_type::<Arguments, ast::Arguments>(py, m)?;
4099+
super::init_type::<Arguments, ast::PythonArguments>(py, m)?;
41004100
super::init_type::<Arg, ast::Arg>(py, m)?;
41014101
super::init_type::<Keyword, ast::Keyword>(py, m)?;
41024102
super::init_type::<Alias, ast::Alias>(py, m)?;

ast-pyo3/src/py_ast.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ impl ToPyAst for ConversionFlag {
7878
}
7979
}
8080

81+
impl<R> ToPyAst for ast::Arguments<R>
82+
where
83+
R: Clone,
84+
ast::PythonArguments<R>: ToPyAst,
85+
{
86+
#[inline]
87+
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
88+
let arguments = self.to_python_arguments();
89+
arguments.to_py_ast(py)
90+
}
91+
}
92+
8193
fn constant_to_object(constant: &ast::Constant, py: Python) -> PyObject {
8294
let cache = ast_cache();
8395
match constant {

ast-pyo3/src/wrapper.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,18 @@ impl<T: ToPyWrapper> ToPyWrapper for Vec<T> {
9393
}
9494
}
9595

96+
impl<R> ToPyWrapper for ast::Arguments<R>
97+
where
98+
Self: Clone,
99+
ast::PythonArguments<R>: ToPyWrapper,
100+
{
101+
#[inline]
102+
fn to_py_wrapper(&'static self, _py: Python) -> PyResult<Py<PyAny>> {
103+
todo!()
104+
// Ok(FunctionArguments(self).to_object(py))
105+
}
106+
}
107+
96108
#[pyclass(module = "rustpython_ast", name = "AST", subclass)]
97109
pub struct Ast;
98110

0 commit comments

Comments
 (0)