Regenerate code with latest ASDL

This commit is contained in:
Zanie 2023-07-10 13:45:36 -05:00
parent 25b23998ad
commit df2b5dfed0
10 changed files with 9288 additions and 19364 deletions

View file

@ -96,6 +96,14 @@ impl<R> PyNode for ast::StmtAssign<R> {
}
}
impl<R> PyNode for ast::StmtTypeAlias<R> {
#[inline]
fn py_type_cache() -> &'static OnceCell<(Py<PyAny>, Py<PyAny>)> {
static PY_TYPE: OnceCell<(Py<PyAny>, Py<PyAny>)> = OnceCell::new();
&PY_TYPE
}
}
impl<R> PyNode for ast::StmtAugAssign<R> {
#[inline]
fn py_type_cache() -> &'static OnceCell<(Py<PyAny>, Py<PyAny>)> {
@ -944,6 +952,38 @@ impl<R> PyNode for ast::TypeIgnoreTypeIgnore<R> {
}
}
impl<R> PyNode for ast::TypeParam<R> {
#[inline]
fn py_type_cache() -> &'static OnceCell<(Py<PyAny>, Py<PyAny>)> {
static PY_TYPE: OnceCell<(Py<PyAny>, Py<PyAny>)> = OnceCell::new();
&PY_TYPE
}
}
impl<R> PyNode for ast::TypeParamTypeVar<R> {
#[inline]
fn py_type_cache() -> &'static OnceCell<(Py<PyAny>, Py<PyAny>)> {
static PY_TYPE: OnceCell<(Py<PyAny>, Py<PyAny>)> = OnceCell::new();
&PY_TYPE
}
}
impl<R> PyNode for ast::TypeParamParamSpec<R> {
#[inline]
fn py_type_cache() -> &'static OnceCell<(Py<PyAny>, Py<PyAny>)> {
static PY_TYPE: OnceCell<(Py<PyAny>, Py<PyAny>)> = OnceCell::new();
&PY_TYPE
}
}
impl<R> PyNode for ast::TypeParamTypeVarTuple<R> {
#[inline]
fn py_type_cache() -> &'static OnceCell<(Py<PyAny>, Py<PyAny>)> {
static PY_TYPE: OnceCell<(Py<PyAny>, Py<PyAny>)> = OnceCell::new();
&PY_TYPE
}
}
impl ToPyAst for ast::ExprContext {
#[inline]
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
@ -1112,6 +1152,7 @@ impl ToPyAst for ast::Stmt<TextRange> {
ast::Stmt::Return(cons) => cons.to_py_ast(py)?,
ast::Stmt::Delete(cons) => cons.to_py_ast(py)?,
ast::Stmt::Assign(cons) => cons.to_py_ast(py)?,
ast::Stmt::TypeAlias(cons) => cons.to_py_ast(py)?,
ast::Stmt::AugAssign(cons) => cons.to_py_ast(py)?,
ast::Stmt::AnnAssign(cons) => cons.to_py_ast(py)?,
ast::Stmt::For(cons) => cons.to_py_ast(py)?,
@ -1150,6 +1191,7 @@ impl ToPyAst for ast::StmtFunctionDef<TextRange> {
decorator_list,
returns,
type_comment,
type_params,
range: _range,
} = self;
@ -1160,6 +1202,7 @@ impl ToPyAst for ast::StmtFunctionDef<TextRange> {
decorator_list.to_py_ast(py)?,
returns.to_py_ast(py)?,
type_comment.to_py_ast(py)?,
type_params.to_py_ast(py)?,
))?;
Ok(instance)
@ -1178,6 +1221,7 @@ impl ToPyAst for ast::StmtAsyncFunctionDef<TextRange> {
decorator_list,
returns,
type_comment,
type_params,
range: _range,
} = self;
@ -1188,6 +1232,7 @@ impl ToPyAst for ast::StmtAsyncFunctionDef<TextRange> {
decorator_list.to_py_ast(py)?,
returns.to_py_ast(py)?,
type_comment.to_py_ast(py)?,
type_params.to_py_ast(py)?,
))?;
Ok(instance)
@ -1205,6 +1250,7 @@ impl ToPyAst for ast::StmtClassDef<TextRange> {
keywords,
body,
decorator_list,
type_params,
range: _range,
} = self;
@ -1214,6 +1260,7 @@ impl ToPyAst for ast::StmtClassDef<TextRange> {
keywords.to_py_ast(py)?,
body.to_py_ast(py)?,
decorator_list.to_py_ast(py)?,
type_params.to_py_ast(py)?,
))?;
Ok(instance)
@ -1274,6 +1321,28 @@ impl ToPyAst for ast::StmtAssign<TextRange> {
}
}
impl ToPyAst for ast::StmtTypeAlias<TextRange> {
#[inline]
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
let cache = Self::py_type_cache().get().unwrap();
let Self {
name,
type_params,
value,
range: _range,
} = self;
let instance = Py::<PyAny>::as_ref(&cache.0, py).call1((
name.to_py_ast(py)?,
type_params.to_py_ast(py)?,
value.to_py_ast(py)?,
))?;
Ok(instance)
}
}
impl ToPyAst for ast::StmtAugAssign<TextRange> {
#[inline]
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
@ -2605,6 +2674,68 @@ impl ToPyAst for ast::TypeIgnoreTypeIgnore<TextRange> {
}
}
impl ToPyAst for ast::TypeParam<TextRange> {
#[inline]
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
let instance = match &self {
ast::TypeParam::TypeVar(cons) => cons.to_py_ast(py)?,
ast::TypeParam::ParamSpec(cons) => cons.to_py_ast(py)?,
ast::TypeParam::TypeVarTuple(cons) => cons.to_py_ast(py)?,
};
Ok(instance)
}
}
impl ToPyAst for ast::TypeParamTypeVar<TextRange> {
#[inline]
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
let cache = Self::py_type_cache().get().unwrap();
let Self {
name,
bound,
range: _range,
} = self;
let instance =
Py::<PyAny>::as_ref(&cache.0, py).call1((name.to_py_ast(py)?, bound.to_py_ast(py)?))?;
Ok(instance)
}
}
impl ToPyAst for ast::TypeParamParamSpec<TextRange> {
#[inline]
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
let cache = Self::py_type_cache().get().unwrap();
let Self {
name,
range: _range,
} = self;
let instance = Py::<PyAny>::as_ref(&cache.0, py).call1((name.to_py_ast(py)?,))?;
Ok(instance)
}
}
impl ToPyAst for ast::TypeParamTypeVarTuple<TextRange> {
#[inline]
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
let cache = Self::py_type_cache().get().unwrap();
let Self {
name,
range: _range,
} = self;
let instance = Py::<PyAny>::as_ref(&cache.0, py).call1((name.to_py_ast(py)?,))?;
Ok(instance)
}
}
impl ToPyAst for ast::Mod<SourceRange> {
#[inline]
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
@ -2696,6 +2827,7 @@ impl ToPyAst for ast::Stmt<SourceRange> {
ast::Stmt::Return(cons) => cons.to_py_ast(py)?,
ast::Stmt::Delete(cons) => cons.to_py_ast(py)?,
ast::Stmt::Assign(cons) => cons.to_py_ast(py)?,
ast::Stmt::TypeAlias(cons) => cons.to_py_ast(py)?,
ast::Stmt::AugAssign(cons) => cons.to_py_ast(py)?,
ast::Stmt::AnnAssign(cons) => cons.to_py_ast(py)?,
ast::Stmt::For(cons) => cons.to_py_ast(py)?,
@ -2734,6 +2866,7 @@ impl ToPyAst for ast::StmtFunctionDef<SourceRange> {
decorator_list,
returns,
type_comment,
type_params,
range: _range,
} = self;
@ -2744,6 +2877,7 @@ impl ToPyAst for ast::StmtFunctionDef<SourceRange> {
decorator_list.to_py_ast(py)?,
returns.to_py_ast(py)?,
type_comment.to_py_ast(py)?,
type_params.to_py_ast(py)?,
))?;
let cache = ast_cache();
@ -2770,6 +2904,7 @@ impl ToPyAst for ast::StmtAsyncFunctionDef<SourceRange> {
decorator_list,
returns,
type_comment,
type_params,
range: _range,
} = self;
@ -2780,6 +2915,7 @@ impl ToPyAst for ast::StmtAsyncFunctionDef<SourceRange> {
decorator_list.to_py_ast(py)?,
returns.to_py_ast(py)?,
type_comment.to_py_ast(py)?,
type_params.to_py_ast(py)?,
))?;
let cache = ast_cache();
@ -2805,6 +2941,7 @@ impl ToPyAst for ast::StmtClassDef<SourceRange> {
keywords,
body,
decorator_list,
type_params,
range: _range,
} = self;
@ -2814,6 +2951,7 @@ impl ToPyAst for ast::StmtClassDef<SourceRange> {
keywords.to_py_ast(py)?,
body.to_py_ast(py)?,
decorator_list.to_py_ast(py)?,
type_params.to_py_ast(py)?,
))?;
let cache = ast_cache();
@ -2906,6 +3044,36 @@ impl ToPyAst for ast::StmtAssign<SourceRange> {
}
}
impl ToPyAst for ast::StmtTypeAlias<SourceRange> {
#[inline]
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
let cache = Self::py_type_cache().get().unwrap();
let Self {
name,
type_params,
value,
range: _range,
} = self;
let instance = Py::<PyAny>::as_ref(&cache.0, py).call1((
name.to_py_ast(py)?,
type_params.to_py_ast(py)?,
value.to_py_ast(py)?,
))?;
let cache = ast_cache();
instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?;
instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?;
if let Some(end) = _range.end {
instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?;
instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?;
}
Ok(instance)
}
}
impl ToPyAst for ast::StmtAugAssign<SourceRange> {
#[inline]
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
@ -4717,6 +4885,92 @@ impl ToPyAst for ast::TypeIgnoreTypeIgnore<SourceRange> {
}
}
impl ToPyAst for ast::TypeParam<SourceRange> {
#[inline]
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
let instance = match &self {
ast::TypeParam::TypeVar(cons) => cons.to_py_ast(py)?,
ast::TypeParam::ParamSpec(cons) => cons.to_py_ast(py)?,
ast::TypeParam::TypeVarTuple(cons) => cons.to_py_ast(py)?,
};
Ok(instance)
}
}
impl ToPyAst for ast::TypeParamTypeVar<SourceRange> {
#[inline]
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
let cache = Self::py_type_cache().get().unwrap();
let Self {
name,
bound,
range: _range,
} = self;
let instance =
Py::<PyAny>::as_ref(&cache.0, py).call1((name.to_py_ast(py)?, bound.to_py_ast(py)?))?;
let cache = ast_cache();
instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?;
instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?;
if let Some(end) = _range.end {
instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?;
instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?;
}
Ok(instance)
}
}
impl ToPyAst for ast::TypeParamParamSpec<SourceRange> {
#[inline]
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
let cache = Self::py_type_cache().get().unwrap();
let Self {
name,
range: _range,
} = self;
let instance = Py::<PyAny>::as_ref(&cache.0, py).call1((name.to_py_ast(py)?,))?;
let cache = ast_cache();
instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?;
instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?;
if let Some(end) = _range.end {
instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?;
instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?;
}
Ok(instance)
}
}
impl ToPyAst for ast::TypeParamTypeVarTuple<SourceRange> {
#[inline]
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
let cache = Self::py_type_cache().get().unwrap();
let Self {
name,
range: _range,
} = self;
let instance = Py::<PyAny>::as_ref(&cache.0, py).call1((name.to_py_ast(py)?,))?;
let cache = ast_cache();
instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?;
instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?;
if let Some(end) = _range.end {
instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?;
instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?;
}
Ok(instance)
}
}
fn init_types(py: Python) -> PyResult<()> {
let ast_module = PyModule::import(py, "_ast")?;
cache_py_type::<ast::Mod>(ast_module)?;
@ -4731,6 +4985,7 @@ fn init_types(py: Python) -> PyResult<()> {
cache_py_type::<ast::StmtReturn>(ast_module)?;
cache_py_type::<ast::StmtDelete>(ast_module)?;
cache_py_type::<ast::StmtAssign>(ast_module)?;
cache_py_type::<ast::StmtTypeAlias>(ast_module)?;
cache_py_type::<ast::StmtAugAssign>(ast_module)?;
cache_py_type::<ast::StmtAnnAssign>(ast_module)?;
cache_py_type::<ast::StmtFor>(ast_module)?;
@ -4837,5 +5092,9 @@ fn init_types(py: Python) -> PyResult<()> {
cache_py_type::<ast::PatternMatchOr>(ast_module)?;
cache_py_type::<ast::TypeIgnore>(ast_module)?;
cache_py_type::<ast::TypeIgnoreTypeIgnore>(ast_module)?;
cache_py_type::<ast::TypeParam>(ast_module)?;
cache_py_type::<ast::TypeParamTypeVar>(ast_module)?;
cache_py_type::<ast::TypeParamParamSpec>(ast_module)?;
cache_py_type::<ast::TypeParamTypeVarTuple>(ast_module)?;
Ok(())
}

View file

@ -222,6 +222,7 @@ impl ToPyWrapper for ast::Stmt<SourceRange> {
Self::Return(cons) => cons.to_py_wrapper(py),
Self::Delete(cons) => cons.to_py_wrapper(py),
Self::Assign(cons) => cons.to_py_wrapper(py),
Self::TypeAlias(cons) => cons.to_py_wrapper(py),
Self::AugAssign(cons) => cons.to_py_wrapper(py),
Self::AnnAssign(cons) => cons.to_py_wrapper(py),
Self::For(cons) => cons.to_py_wrapper(py),
@ -310,6 +311,12 @@ impl StmtFunctionDef {
fn get_type_comment(&self, py: Python) -> PyResult<PyObject> {
self.0.type_comment.to_py_wrapper(py)
}
#[getter]
#[inline]
fn get_type_params(&self, py: Python) -> PyResult<PyObject> {
self.0.type_params.to_py_wrapper(py)
}
}
#[pyclass(module="rustpython_ast.located", name="_AsyncFunctionDef", extends=Stmt, frozen)]
@ -375,6 +382,12 @@ impl StmtAsyncFunctionDef {
fn get_type_comment(&self, py: Python) -> PyResult<PyObject> {
self.0.type_comment.to_py_wrapper(py)
}
#[getter]
#[inline]
fn get_type_params(&self, py: Python) -> PyResult<PyObject> {
self.0.type_params.to_py_wrapper(py)
}
}
#[pyclass(module="rustpython_ast.located", name="_ClassDef", extends=Stmt, frozen)]
@ -434,6 +447,12 @@ impl StmtClassDef {
fn get_decorator_list(&self, py: Python) -> PyResult<PyObject> {
self.0.decorator_list.to_py_wrapper(py)
}
#[getter]
#[inline]
fn get_type_params(&self, py: Python) -> PyResult<PyObject> {
self.0.type_params.to_py_wrapper(py)
}
}
#[pyclass(module="rustpython_ast.located", name="_Return", extends=Stmt, frozen)]
@ -553,6 +572,53 @@ impl StmtAssign {
}
}
#[pyclass(module="rustpython_ast.located", name="_TypeAlias", extends=Stmt, frozen)]
#[derive(Clone, Debug)]
pub struct StmtTypeAlias(pub &'static ast::StmtTypeAlias<SourceRange>);
impl From<&'static ast::StmtTypeAlias<SourceRange>> for StmtTypeAlias {
fn from(node: &'static ast::StmtTypeAlias<SourceRange>) -> Self {
StmtTypeAlias(node)
}
}
impl ToPyObject for StmtTypeAlias {
fn to_object(&self, py: Python) -> PyObject {
let initializer = PyClassInitializer::from(Ast)
.add_subclass(Stmt)
.add_subclass(self.clone());
Py::new(py, initializer).unwrap().into_py(py)
}
}
impl ToPyWrapper for ast::StmtTypeAlias<SourceRange> {
#[inline]
fn to_py_wrapper(&'static self, py: Python) -> PyResult<Py<PyAny>> {
Ok(StmtTypeAlias(self).to_object(py))
}
}
#[pymethods]
impl StmtTypeAlias {
#[getter]
#[inline]
fn get_name(&self, py: Python) -> PyResult<PyObject> {
self.0.name.to_py_wrapper(py)
}
#[getter]
#[inline]
fn get_type_params(&self, py: Python) -> PyResult<PyObject> {
self.0.type_params.to_py_wrapper(py)
}
#[getter]
#[inline]
fn get_value(&self, py: Python) -> PyResult<PyObject> {
self.0.value.to_py_wrapper(py)
}
}
#[pyclass(module="rustpython_ast.located", name="_AugAssign", extends=Stmt, frozen)]
#[derive(Clone, Debug)]
pub struct StmtAugAssign(pub &'static ast::StmtAugAssign<SourceRange>);
@ -3993,6 +4059,152 @@ impl TypeIgnoreTypeIgnore {
}
}
#[pyclass(module="rustpython_ast.located", name="_type_param", extends=super::Ast, frozen, subclass)]
#[derive(Clone, Debug)]
pub struct TypeParam;
impl From<&'static ast::TypeParam<SourceRange>> for TypeParam {
fn from(_node: &'static ast::TypeParam<SourceRange>) -> Self {
TypeParam
}
}
#[pymethods]
impl TypeParam {
#[new]
fn new() -> PyClassInitializer<Self> {
PyClassInitializer::from(Ast).add_subclass(Self)
}
}
impl ToPyObject for TypeParam {
fn to_object(&self, py: Python) -> PyObject {
let initializer = Self::new();
Py::new(py, initializer).unwrap().into_py(py)
}
}
impl ToPyWrapper for ast::TypeParam<SourceRange> {
#[inline]
fn to_py_wrapper(&'static self, py: Python) -> PyResult<Py<PyAny>> {
match &self {
Self::TypeVar(cons) => cons.to_py_wrapper(py),
Self::ParamSpec(cons) => cons.to_py_wrapper(py),
Self::TypeVarTuple(cons) => cons.to_py_wrapper(py),
}
}
}
#[pyclass(module="rustpython_ast.located", name="_TypeVar", extends=TypeParam, frozen)]
#[derive(Clone, Debug)]
pub struct TypeParamTypeVar(pub &'static ast::TypeParamTypeVar<SourceRange>);
impl From<&'static ast::TypeParamTypeVar<SourceRange>> for TypeParamTypeVar {
fn from(node: &'static ast::TypeParamTypeVar<SourceRange>) -> Self {
TypeParamTypeVar(node)
}
}
impl ToPyObject for TypeParamTypeVar {
fn to_object(&self, py: Python) -> PyObject {
let initializer = PyClassInitializer::from(Ast)
.add_subclass(TypeParam)
.add_subclass(self.clone());
Py::new(py, initializer).unwrap().into_py(py)
}
}
impl ToPyWrapper for ast::TypeParamTypeVar<SourceRange> {
#[inline]
fn to_py_wrapper(&'static self, py: Python) -> PyResult<Py<PyAny>> {
Ok(TypeParamTypeVar(self).to_object(py))
}
}
#[pymethods]
impl TypeParamTypeVar {
#[getter]
#[inline]
fn get_name(&self, py: Python) -> PyResult<PyObject> {
self.0.name.to_py_wrapper(py)
}
#[getter]
#[inline]
fn get_bound(&self, py: Python) -> PyResult<PyObject> {
self.0.bound.to_py_wrapper(py)
}
}
#[pyclass(module="rustpython_ast.located", name="_ParamSpec", extends=TypeParam, frozen)]
#[derive(Clone, Debug)]
pub struct TypeParamParamSpec(pub &'static ast::TypeParamParamSpec<SourceRange>);
impl From<&'static ast::TypeParamParamSpec<SourceRange>> for TypeParamParamSpec {
fn from(node: &'static ast::TypeParamParamSpec<SourceRange>) -> Self {
TypeParamParamSpec(node)
}
}
impl ToPyObject for TypeParamParamSpec {
fn to_object(&self, py: Python) -> PyObject {
let initializer = PyClassInitializer::from(Ast)
.add_subclass(TypeParam)
.add_subclass(self.clone());
Py::new(py, initializer).unwrap().into_py(py)
}
}
impl ToPyWrapper for ast::TypeParamParamSpec<SourceRange> {
#[inline]
fn to_py_wrapper(&'static self, py: Python) -> PyResult<Py<PyAny>> {
Ok(TypeParamParamSpec(self).to_object(py))
}
}
#[pymethods]
impl TypeParamParamSpec {
#[getter]
#[inline]
fn get_name(&self, py: Python) -> PyResult<PyObject> {
self.0.name.to_py_wrapper(py)
}
}
#[pyclass(module="rustpython_ast.located", name="_TypeVarTuple", extends=TypeParam, frozen)]
#[derive(Clone, Debug)]
pub struct TypeParamTypeVarTuple(pub &'static ast::TypeParamTypeVarTuple<SourceRange>);
impl From<&'static ast::TypeParamTypeVarTuple<SourceRange>> for TypeParamTypeVarTuple {
fn from(node: &'static ast::TypeParamTypeVarTuple<SourceRange>) -> Self {
TypeParamTypeVarTuple(node)
}
}
impl ToPyObject for TypeParamTypeVarTuple {
fn to_object(&self, py: Python) -> PyObject {
let initializer = PyClassInitializer::from(Ast)
.add_subclass(TypeParam)
.add_subclass(self.clone());
Py::new(py, initializer).unwrap().into_py(py)
}
}
impl ToPyWrapper for ast::TypeParamTypeVarTuple<SourceRange> {
#[inline]
fn to_py_wrapper(&'static self, py: Python) -> PyResult<Py<PyAny>> {
Ok(TypeParamTypeVarTuple(self).to_object(py))
}
}
#[pymethods]
impl TypeParamTypeVarTuple {
#[getter]
#[inline]
fn get_name(&self, py: Python) -> PyResult<PyObject> {
self.0.name.to_py_wrapper(py)
}
}
impl ToPyWrapper for ast::ExprContext {
#[inline]
fn to_py_wrapper(&self, py: Python) -> PyResult<Py<PyAny>> {
@ -4303,6 +4515,7 @@ pub fn add_to_module(py: Python, m: &PyModule) -> PyResult<()> {
super::init_type::<StmtReturn, ast::StmtReturn>(py, m)?;
super::init_type::<StmtDelete, ast::StmtDelete>(py, m)?;
super::init_type::<StmtAssign, ast::StmtAssign>(py, m)?;
super::init_type::<StmtTypeAlias, ast::StmtTypeAlias>(py, m)?;
super::init_type::<StmtAugAssign, ast::StmtAugAssign>(py, m)?;
super::init_type::<StmtAnnAssign, ast::StmtAnnAssign>(py, m)?;
super::init_type::<StmtFor, ast::StmtFor>(py, m)?;
@ -4409,5 +4622,9 @@ pub fn add_to_module(py: Python, m: &PyModule) -> PyResult<()> {
super::init_type::<PatternMatchOr, ast::PatternMatchOr>(py, m)?;
super::init_type::<TypeIgnore, ast::TypeIgnore>(py, m)?;
super::init_type::<TypeIgnoreTypeIgnore, ast::TypeIgnoreTypeIgnore>(py, m)?;
super::init_type::<TypeParam, ast::TypeParam>(py, m)?;
super::init_type::<TypeParamTypeVar, ast::TypeParamTypeVar>(py, m)?;
super::init_type::<TypeParamParamSpec, ast::TypeParamParamSpec>(py, m)?;
super::init_type::<TypeParamTypeVarTuple, ast::TypeParamTypeVarTuple>(py, m)?;
Ok(())
}

View file

@ -222,6 +222,7 @@ impl ToPyWrapper for ast::Stmt<TextRange> {
Self::Return(cons) => cons.to_py_wrapper(py),
Self::Delete(cons) => cons.to_py_wrapper(py),
Self::Assign(cons) => cons.to_py_wrapper(py),
Self::TypeAlias(cons) => cons.to_py_wrapper(py),
Self::AugAssign(cons) => cons.to_py_wrapper(py),
Self::AnnAssign(cons) => cons.to_py_wrapper(py),
Self::For(cons) => cons.to_py_wrapper(py),
@ -310,6 +311,12 @@ impl StmtFunctionDef {
fn get_type_comment(&self, py: Python) -> PyResult<PyObject> {
self.0.type_comment.to_py_wrapper(py)
}
#[getter]
#[inline]
fn get_type_params(&self, py: Python) -> PyResult<PyObject> {
self.0.type_params.to_py_wrapper(py)
}
}
#[pyclass(module="rustpython_ast.ranged", name="_AsyncFunctionDef", extends=Stmt, frozen)]
@ -375,6 +382,12 @@ impl StmtAsyncFunctionDef {
fn get_type_comment(&self, py: Python) -> PyResult<PyObject> {
self.0.type_comment.to_py_wrapper(py)
}
#[getter]
#[inline]
fn get_type_params(&self, py: Python) -> PyResult<PyObject> {
self.0.type_params.to_py_wrapper(py)
}
}
#[pyclass(module="rustpython_ast.ranged", name="_ClassDef", extends=Stmt, frozen)]
@ -434,6 +447,12 @@ impl StmtClassDef {
fn get_decorator_list(&self, py: Python) -> PyResult<PyObject> {
self.0.decorator_list.to_py_wrapper(py)
}
#[getter]
#[inline]
fn get_type_params(&self, py: Python) -> PyResult<PyObject> {
self.0.type_params.to_py_wrapper(py)
}
}
#[pyclass(module="rustpython_ast.ranged", name="_Return", extends=Stmt, frozen)]
@ -553,6 +572,53 @@ impl StmtAssign {
}
}
#[pyclass(module="rustpython_ast.ranged", name="_TypeAlias", extends=Stmt, frozen)]
#[derive(Clone, Debug)]
pub struct StmtTypeAlias(pub &'static ast::StmtTypeAlias<TextRange>);
impl From<&'static ast::StmtTypeAlias<TextRange>> for StmtTypeAlias {
fn from(node: &'static ast::StmtTypeAlias<TextRange>) -> Self {
StmtTypeAlias(node)
}
}
impl ToPyObject for StmtTypeAlias {
fn to_object(&self, py: Python) -> PyObject {
let initializer = PyClassInitializer::from(Ast)
.add_subclass(Stmt)
.add_subclass(self.clone());
Py::new(py, initializer).unwrap().into_py(py)
}
}
impl ToPyWrapper for ast::StmtTypeAlias<TextRange> {
#[inline]
fn to_py_wrapper(&'static self, py: Python) -> PyResult<Py<PyAny>> {
Ok(StmtTypeAlias(self).to_object(py))
}
}
#[pymethods]
impl StmtTypeAlias {
#[getter]
#[inline]
fn get_name(&self, py: Python) -> PyResult<PyObject> {
self.0.name.to_py_wrapper(py)
}
#[getter]
#[inline]
fn get_type_params(&self, py: Python) -> PyResult<PyObject> {
self.0.type_params.to_py_wrapper(py)
}
#[getter]
#[inline]
fn get_value(&self, py: Python) -> PyResult<PyObject> {
self.0.value.to_py_wrapper(py)
}
}
#[pyclass(module="rustpython_ast.ranged", name="_AugAssign", extends=Stmt, frozen)]
#[derive(Clone, Debug)]
pub struct StmtAugAssign(pub &'static ast::StmtAugAssign<TextRange>);
@ -3993,6 +4059,152 @@ impl TypeIgnoreTypeIgnore {
}
}
#[pyclass(module="rustpython_ast.ranged", name="_type_param", extends=super::Ast, frozen, subclass)]
#[derive(Clone, Debug)]
pub struct TypeParam;
impl From<&'static ast::TypeParam<TextRange>> for TypeParam {
fn from(_node: &'static ast::TypeParam<TextRange>) -> Self {
TypeParam
}
}
#[pymethods]
impl TypeParam {
#[new]
fn new() -> PyClassInitializer<Self> {
PyClassInitializer::from(Ast).add_subclass(Self)
}
}
impl ToPyObject for TypeParam {
fn to_object(&self, py: Python) -> PyObject {
let initializer = Self::new();
Py::new(py, initializer).unwrap().into_py(py)
}
}
impl ToPyWrapper for ast::TypeParam<TextRange> {
#[inline]
fn to_py_wrapper(&'static self, py: Python) -> PyResult<Py<PyAny>> {
match &self {
Self::TypeVar(cons) => cons.to_py_wrapper(py),
Self::ParamSpec(cons) => cons.to_py_wrapper(py),
Self::TypeVarTuple(cons) => cons.to_py_wrapper(py),
}
}
}
#[pyclass(module="rustpython_ast.ranged", name="_TypeVar", extends=TypeParam, frozen)]
#[derive(Clone, Debug)]
pub struct TypeParamTypeVar(pub &'static ast::TypeParamTypeVar<TextRange>);
impl From<&'static ast::TypeParamTypeVar<TextRange>> for TypeParamTypeVar {
fn from(node: &'static ast::TypeParamTypeVar<TextRange>) -> Self {
TypeParamTypeVar(node)
}
}
impl ToPyObject for TypeParamTypeVar {
fn to_object(&self, py: Python) -> PyObject {
let initializer = PyClassInitializer::from(Ast)
.add_subclass(TypeParam)
.add_subclass(self.clone());
Py::new(py, initializer).unwrap().into_py(py)
}
}
impl ToPyWrapper for ast::TypeParamTypeVar<TextRange> {
#[inline]
fn to_py_wrapper(&'static self, py: Python) -> PyResult<Py<PyAny>> {
Ok(TypeParamTypeVar(self).to_object(py))
}
}
#[pymethods]
impl TypeParamTypeVar {
#[getter]
#[inline]
fn get_name(&self, py: Python) -> PyResult<PyObject> {
self.0.name.to_py_wrapper(py)
}
#[getter]
#[inline]
fn get_bound(&self, py: Python) -> PyResult<PyObject> {
self.0.bound.to_py_wrapper(py)
}
}
#[pyclass(module="rustpython_ast.ranged", name="_ParamSpec", extends=TypeParam, frozen)]
#[derive(Clone, Debug)]
pub struct TypeParamParamSpec(pub &'static ast::TypeParamParamSpec<TextRange>);
impl From<&'static ast::TypeParamParamSpec<TextRange>> for TypeParamParamSpec {
fn from(node: &'static ast::TypeParamParamSpec<TextRange>) -> Self {
TypeParamParamSpec(node)
}
}
impl ToPyObject for TypeParamParamSpec {
fn to_object(&self, py: Python) -> PyObject {
let initializer = PyClassInitializer::from(Ast)
.add_subclass(TypeParam)
.add_subclass(self.clone());
Py::new(py, initializer).unwrap().into_py(py)
}
}
impl ToPyWrapper for ast::TypeParamParamSpec<TextRange> {
#[inline]
fn to_py_wrapper(&'static self, py: Python) -> PyResult<Py<PyAny>> {
Ok(TypeParamParamSpec(self).to_object(py))
}
}
#[pymethods]
impl TypeParamParamSpec {
#[getter]
#[inline]
fn get_name(&self, py: Python) -> PyResult<PyObject> {
self.0.name.to_py_wrapper(py)
}
}
#[pyclass(module="rustpython_ast.ranged", name="_TypeVarTuple", extends=TypeParam, frozen)]
#[derive(Clone, Debug)]
pub struct TypeParamTypeVarTuple(pub &'static ast::TypeParamTypeVarTuple<TextRange>);
impl From<&'static ast::TypeParamTypeVarTuple<TextRange>> for TypeParamTypeVarTuple {
fn from(node: &'static ast::TypeParamTypeVarTuple<TextRange>) -> Self {
TypeParamTypeVarTuple(node)
}
}
impl ToPyObject for TypeParamTypeVarTuple {
fn to_object(&self, py: Python) -> PyObject {
let initializer = PyClassInitializer::from(Ast)
.add_subclass(TypeParam)
.add_subclass(self.clone());
Py::new(py, initializer).unwrap().into_py(py)
}
}
impl ToPyWrapper for ast::TypeParamTypeVarTuple<TextRange> {
#[inline]
fn to_py_wrapper(&'static self, py: Python) -> PyResult<Py<PyAny>> {
Ok(TypeParamTypeVarTuple(self).to_object(py))
}
}
#[pymethods]
impl TypeParamTypeVarTuple {
#[getter]
#[inline]
fn get_name(&self, py: Python) -> PyResult<PyObject> {
self.0.name.to_py_wrapper(py)
}
}
pub fn add_to_module(py: Python, m: &PyModule) -> PyResult<()> {
super::init_module(py, m)?;
super::init_type::<Mod, ast::Mod>(py, m)?;
@ -4007,6 +4219,7 @@ pub fn add_to_module(py: Python, m: &PyModule) -> PyResult<()> {
super::init_type::<StmtReturn, ast::StmtReturn>(py, m)?;
super::init_type::<StmtDelete, ast::StmtDelete>(py, m)?;
super::init_type::<StmtAssign, ast::StmtAssign>(py, m)?;
super::init_type::<StmtTypeAlias, ast::StmtTypeAlias>(py, m)?;
super::init_type::<StmtAugAssign, ast::StmtAugAssign>(py, m)?;
super::init_type::<StmtAnnAssign, ast::StmtAnnAssign>(py, m)?;
super::init_type::<StmtFor, ast::StmtFor>(py, m)?;
@ -4113,5 +4326,9 @@ pub fn add_to_module(py: Python, m: &PyModule) -> PyResult<()> {
super::init_type::<PatternMatchOr, ast::PatternMatchOr>(py, m)?;
super::init_type::<TypeIgnore, ast::TypeIgnore>(py, m)?;
super::init_type::<TypeIgnoreTypeIgnore, ast::TypeIgnoreTypeIgnore>(py, m)?;
super::init_type::<TypeParam, ast::TypeParam>(py, m)?;
super::init_type::<TypeParamTypeVar, ast::TypeParamTypeVar>(py, m)?;
super::init_type::<TypeParamParamSpec, ast::TypeParamParamSpec>(py, m)?;
super::init_type::<TypeParamTypeVarTuple, ast::TypeParamTypeVarTuple>(py, m)?;
Ok(())
}