mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-10 06:35:17 +00:00
Regenerate code with latest ASDL
This commit is contained in:
parent
25b23998ad
commit
df2b5dfed0
10 changed files with 9288 additions and 19364 deletions
|
@ -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> {
|
impl<R> PyNode for ast::StmtAugAssign<R> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn py_type_cache() -> &'static OnceCell<(Py<PyAny>, Py<PyAny>)> {
|
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 {
|
impl ToPyAst for ast::ExprContext {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
|
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::Return(cons) => cons.to_py_ast(py)?,
|
||||||
ast::Stmt::Delete(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::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::AugAssign(cons) => cons.to_py_ast(py)?,
|
||||||
ast::Stmt::AnnAssign(cons) => cons.to_py_ast(py)?,
|
ast::Stmt::AnnAssign(cons) => cons.to_py_ast(py)?,
|
||||||
ast::Stmt::For(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,
|
decorator_list,
|
||||||
returns,
|
returns,
|
||||||
type_comment,
|
type_comment,
|
||||||
|
type_params,
|
||||||
range: _range,
|
range: _range,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
|
@ -1160,6 +1202,7 @@ impl ToPyAst for ast::StmtFunctionDef<TextRange> {
|
||||||
decorator_list.to_py_ast(py)?,
|
decorator_list.to_py_ast(py)?,
|
||||||
returns.to_py_ast(py)?,
|
returns.to_py_ast(py)?,
|
||||||
type_comment.to_py_ast(py)?,
|
type_comment.to_py_ast(py)?,
|
||||||
|
type_params.to_py_ast(py)?,
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
Ok(instance)
|
Ok(instance)
|
||||||
|
@ -1178,6 +1221,7 @@ impl ToPyAst for ast::StmtAsyncFunctionDef<TextRange> {
|
||||||
decorator_list,
|
decorator_list,
|
||||||
returns,
|
returns,
|
||||||
type_comment,
|
type_comment,
|
||||||
|
type_params,
|
||||||
range: _range,
|
range: _range,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
|
@ -1188,6 +1232,7 @@ impl ToPyAst for ast::StmtAsyncFunctionDef<TextRange> {
|
||||||
decorator_list.to_py_ast(py)?,
|
decorator_list.to_py_ast(py)?,
|
||||||
returns.to_py_ast(py)?,
|
returns.to_py_ast(py)?,
|
||||||
type_comment.to_py_ast(py)?,
|
type_comment.to_py_ast(py)?,
|
||||||
|
type_params.to_py_ast(py)?,
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
Ok(instance)
|
Ok(instance)
|
||||||
|
@ -1205,6 +1250,7 @@ impl ToPyAst for ast::StmtClassDef<TextRange> {
|
||||||
keywords,
|
keywords,
|
||||||
body,
|
body,
|
||||||
decorator_list,
|
decorator_list,
|
||||||
|
type_params,
|
||||||
range: _range,
|
range: _range,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
|
@ -1214,6 +1260,7 @@ impl ToPyAst for ast::StmtClassDef<TextRange> {
|
||||||
keywords.to_py_ast(py)?,
|
keywords.to_py_ast(py)?,
|
||||||
body.to_py_ast(py)?,
|
body.to_py_ast(py)?,
|
||||||
decorator_list.to_py_ast(py)?,
|
decorator_list.to_py_ast(py)?,
|
||||||
|
type_params.to_py_ast(py)?,
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
Ok(instance)
|
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> {
|
impl ToPyAst for ast::StmtAugAssign<TextRange> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
|
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> {
|
impl ToPyAst for ast::Mod<SourceRange> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
|
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::Return(cons) => cons.to_py_ast(py)?,
|
||||||
ast::Stmt::Delete(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::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::AugAssign(cons) => cons.to_py_ast(py)?,
|
||||||
ast::Stmt::AnnAssign(cons) => cons.to_py_ast(py)?,
|
ast::Stmt::AnnAssign(cons) => cons.to_py_ast(py)?,
|
||||||
ast::Stmt::For(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,
|
decorator_list,
|
||||||
returns,
|
returns,
|
||||||
type_comment,
|
type_comment,
|
||||||
|
type_params,
|
||||||
range: _range,
|
range: _range,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
|
@ -2744,6 +2877,7 @@ impl ToPyAst for ast::StmtFunctionDef<SourceRange> {
|
||||||
decorator_list.to_py_ast(py)?,
|
decorator_list.to_py_ast(py)?,
|
||||||
returns.to_py_ast(py)?,
|
returns.to_py_ast(py)?,
|
||||||
type_comment.to_py_ast(py)?,
|
type_comment.to_py_ast(py)?,
|
||||||
|
type_params.to_py_ast(py)?,
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
let cache = ast_cache();
|
let cache = ast_cache();
|
||||||
|
@ -2770,6 +2904,7 @@ impl ToPyAst for ast::StmtAsyncFunctionDef<SourceRange> {
|
||||||
decorator_list,
|
decorator_list,
|
||||||
returns,
|
returns,
|
||||||
type_comment,
|
type_comment,
|
||||||
|
type_params,
|
||||||
range: _range,
|
range: _range,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
|
@ -2780,6 +2915,7 @@ impl ToPyAst for ast::StmtAsyncFunctionDef<SourceRange> {
|
||||||
decorator_list.to_py_ast(py)?,
|
decorator_list.to_py_ast(py)?,
|
||||||
returns.to_py_ast(py)?,
|
returns.to_py_ast(py)?,
|
||||||
type_comment.to_py_ast(py)?,
|
type_comment.to_py_ast(py)?,
|
||||||
|
type_params.to_py_ast(py)?,
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
let cache = ast_cache();
|
let cache = ast_cache();
|
||||||
|
@ -2805,6 +2941,7 @@ impl ToPyAst for ast::StmtClassDef<SourceRange> {
|
||||||
keywords,
|
keywords,
|
||||||
body,
|
body,
|
||||||
decorator_list,
|
decorator_list,
|
||||||
|
type_params,
|
||||||
range: _range,
|
range: _range,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
|
@ -2814,6 +2951,7 @@ impl ToPyAst for ast::StmtClassDef<SourceRange> {
|
||||||
keywords.to_py_ast(py)?,
|
keywords.to_py_ast(py)?,
|
||||||
body.to_py_ast(py)?,
|
body.to_py_ast(py)?,
|
||||||
decorator_list.to_py_ast(py)?,
|
decorator_list.to_py_ast(py)?,
|
||||||
|
type_params.to_py_ast(py)?,
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
let cache = ast_cache();
|
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> {
|
impl ToPyAst for ast::StmtAugAssign<SourceRange> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
|
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<()> {
|
fn init_types(py: Python) -> PyResult<()> {
|
||||||
let ast_module = PyModule::import(py, "_ast")?;
|
let ast_module = PyModule::import(py, "_ast")?;
|
||||||
cache_py_type::<ast::Mod>(ast_module)?;
|
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::StmtReturn>(ast_module)?;
|
||||||
cache_py_type::<ast::StmtDelete>(ast_module)?;
|
cache_py_type::<ast::StmtDelete>(ast_module)?;
|
||||||
cache_py_type::<ast::StmtAssign>(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::StmtAugAssign>(ast_module)?;
|
||||||
cache_py_type::<ast::StmtAnnAssign>(ast_module)?;
|
cache_py_type::<ast::StmtAnnAssign>(ast_module)?;
|
||||||
cache_py_type::<ast::StmtFor>(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::PatternMatchOr>(ast_module)?;
|
||||||
cache_py_type::<ast::TypeIgnore>(ast_module)?;
|
cache_py_type::<ast::TypeIgnore>(ast_module)?;
|
||||||
cache_py_type::<ast::TypeIgnoreTypeIgnore>(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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,6 +222,7 @@ impl ToPyWrapper for ast::Stmt<SourceRange> {
|
||||||
Self::Return(cons) => cons.to_py_wrapper(py),
|
Self::Return(cons) => cons.to_py_wrapper(py),
|
||||||
Self::Delete(cons) => cons.to_py_wrapper(py),
|
Self::Delete(cons) => cons.to_py_wrapper(py),
|
||||||
Self::Assign(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::AugAssign(cons) => cons.to_py_wrapper(py),
|
||||||
Self::AnnAssign(cons) => cons.to_py_wrapper(py),
|
Self::AnnAssign(cons) => cons.to_py_wrapper(py),
|
||||||
Self::For(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> {
|
fn get_type_comment(&self, py: Python) -> PyResult<PyObject> {
|
||||||
self.0.type_comment.to_py_wrapper(py)
|
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)]
|
#[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> {
|
fn get_type_comment(&self, py: Python) -> PyResult<PyObject> {
|
||||||
self.0.type_comment.to_py_wrapper(py)
|
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)]
|
#[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> {
|
fn get_decorator_list(&self, py: Python) -> PyResult<PyObject> {
|
||||||
self.0.decorator_list.to_py_wrapper(py)
|
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)]
|
#[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)]
|
#[pyclass(module="rustpython_ast.located", name="_AugAssign", extends=Stmt, frozen)]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct StmtAugAssign(pub &'static ast::StmtAugAssign<SourceRange>);
|
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 {
|
impl ToPyWrapper for ast::ExprContext {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_py_wrapper(&self, py: Python) -> PyResult<Py<PyAny>> {
|
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::<StmtReturn, ast::StmtReturn>(py, m)?;
|
||||||
super::init_type::<StmtDelete, ast::StmtDelete>(py, m)?;
|
super::init_type::<StmtDelete, ast::StmtDelete>(py, m)?;
|
||||||
super::init_type::<StmtAssign, ast::StmtAssign>(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::<StmtAugAssign, ast::StmtAugAssign>(py, m)?;
|
||||||
super::init_type::<StmtAnnAssign, ast::StmtAnnAssign>(py, m)?;
|
super::init_type::<StmtAnnAssign, ast::StmtAnnAssign>(py, m)?;
|
||||||
super::init_type::<StmtFor, ast::StmtFor>(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::<PatternMatchOr, ast::PatternMatchOr>(py, m)?;
|
||||||
super::init_type::<TypeIgnore, ast::TypeIgnore>(py, m)?;
|
super::init_type::<TypeIgnore, ast::TypeIgnore>(py, m)?;
|
||||||
super::init_type::<TypeIgnoreTypeIgnore, ast::TypeIgnoreTypeIgnore>(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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,6 +222,7 @@ impl ToPyWrapper for ast::Stmt<TextRange> {
|
||||||
Self::Return(cons) => cons.to_py_wrapper(py),
|
Self::Return(cons) => cons.to_py_wrapper(py),
|
||||||
Self::Delete(cons) => cons.to_py_wrapper(py),
|
Self::Delete(cons) => cons.to_py_wrapper(py),
|
||||||
Self::Assign(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::AugAssign(cons) => cons.to_py_wrapper(py),
|
||||||
Self::AnnAssign(cons) => cons.to_py_wrapper(py),
|
Self::AnnAssign(cons) => cons.to_py_wrapper(py),
|
||||||
Self::For(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> {
|
fn get_type_comment(&self, py: Python) -> PyResult<PyObject> {
|
||||||
self.0.type_comment.to_py_wrapper(py)
|
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)]
|
#[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> {
|
fn get_type_comment(&self, py: Python) -> PyResult<PyObject> {
|
||||||
self.0.type_comment.to_py_wrapper(py)
|
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)]
|
#[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> {
|
fn get_decorator_list(&self, py: Python) -> PyResult<PyObject> {
|
||||||
self.0.decorator_list.to_py_wrapper(py)
|
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)]
|
#[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)]
|
#[pyclass(module="rustpython_ast.ranged", name="_AugAssign", extends=Stmt, frozen)]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct StmtAugAssign(pub &'static ast::StmtAugAssign<TextRange>);
|
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<()> {
|
pub fn add_to_module(py: Python, m: &PyModule) -> PyResult<()> {
|
||||||
super::init_module(py, m)?;
|
super::init_module(py, m)?;
|
||||||
super::init_type::<Mod, ast::Mod>(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::<StmtReturn, ast::StmtReturn>(py, m)?;
|
||||||
super::init_type::<StmtDelete, ast::StmtDelete>(py, m)?;
|
super::init_type::<StmtDelete, ast::StmtDelete>(py, m)?;
|
||||||
super::init_type::<StmtAssign, ast::StmtAssign>(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::<StmtAugAssign, ast::StmtAugAssign>(py, m)?;
|
||||||
super::init_type::<StmtAnnAssign, ast::StmtAnnAssign>(py, m)?;
|
super::init_type::<StmtAnnAssign, ast::StmtAnnAssign>(py, m)?;
|
||||||
super::init_type::<StmtFor, ast::StmtFor>(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::<PatternMatchOr, ast::PatternMatchOr>(py, m)?;
|
||||||
super::init_type::<TypeIgnore, ast::TypeIgnore>(py, m)?;
|
super::init_type::<TypeIgnore, ast::TypeIgnore>(py, m)?;
|
||||||
super::init_type::<TypeIgnoreTypeIgnore, ast::TypeIgnoreTypeIgnore>(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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,6 +108,12 @@ pub trait Fold<U> {
|
||||||
) -> Result<StmtAssign<Self::TargetU>, Self::Error> {
|
) -> Result<StmtAssign<Self::TargetU>, Self::Error> {
|
||||||
fold_stmt_assign(self, node)
|
fold_stmt_assign(self, node)
|
||||||
}
|
}
|
||||||
|
fn fold_stmt_type_alias(
|
||||||
|
&mut self,
|
||||||
|
node: StmtTypeAlias<U>,
|
||||||
|
) -> Result<StmtTypeAlias<Self::TargetU>, Self::Error> {
|
||||||
|
fold_stmt_type_alias(self, node)
|
||||||
|
}
|
||||||
fn fold_stmt_aug_assign(
|
fn fold_stmt_aug_assign(
|
||||||
&mut self,
|
&mut self,
|
||||||
node: StmtAugAssign<U>,
|
node: StmtAugAssign<U>,
|
||||||
|
@ -507,6 +513,30 @@ pub trait Fold<U> {
|
||||||
) -> Result<TypeIgnoreTypeIgnore<Self::TargetU>, Self::Error> {
|
) -> Result<TypeIgnoreTypeIgnore<Self::TargetU>, Self::Error> {
|
||||||
fold_type_ignore_type_ignore(self, node)
|
fold_type_ignore_type_ignore(self, node)
|
||||||
}
|
}
|
||||||
|
fn fold_type_param(
|
||||||
|
&mut self,
|
||||||
|
node: TypeParam<U>,
|
||||||
|
) -> Result<TypeParam<Self::TargetU>, Self::Error> {
|
||||||
|
fold_type_param(self, node)
|
||||||
|
}
|
||||||
|
fn fold_type_param_type_var(
|
||||||
|
&mut self,
|
||||||
|
node: TypeParamTypeVar<U>,
|
||||||
|
) -> Result<TypeParamTypeVar<Self::TargetU>, Self::Error> {
|
||||||
|
fold_type_param_type_var(self, node)
|
||||||
|
}
|
||||||
|
fn fold_type_param_param_spec(
|
||||||
|
&mut self,
|
||||||
|
node: TypeParamParamSpec<U>,
|
||||||
|
) -> Result<TypeParamParamSpec<Self::TargetU>, Self::Error> {
|
||||||
|
fold_type_param_param_spec(self, node)
|
||||||
|
}
|
||||||
|
fn fold_type_param_type_var_tuple(
|
||||||
|
&mut self,
|
||||||
|
node: TypeParamTypeVarTuple<U>,
|
||||||
|
) -> Result<TypeParamTypeVarTuple<Self::TargetU>, Self::Error> {
|
||||||
|
fold_type_param_type_var_tuple(self, node)
|
||||||
|
}
|
||||||
fn fold_arg_with_default(
|
fn fold_arg_with_default(
|
||||||
&mut self,
|
&mut self,
|
||||||
node: ArgWithDefault<U>,
|
node: ArgWithDefault<U>,
|
||||||
|
@ -653,6 +683,7 @@ pub fn fold_stmt<U, F: Fold<U> + ?Sized>(
|
||||||
Stmt::Return(cons) => Stmt::Return(Foldable::fold(cons, folder)?),
|
Stmt::Return(cons) => Stmt::Return(Foldable::fold(cons, folder)?),
|
||||||
Stmt::Delete(cons) => Stmt::Delete(Foldable::fold(cons, folder)?),
|
Stmt::Delete(cons) => Stmt::Delete(Foldable::fold(cons, folder)?),
|
||||||
Stmt::Assign(cons) => Stmt::Assign(Foldable::fold(cons, folder)?),
|
Stmt::Assign(cons) => Stmt::Assign(Foldable::fold(cons, folder)?),
|
||||||
|
Stmt::TypeAlias(cons) => Stmt::TypeAlias(Foldable::fold(cons, folder)?),
|
||||||
Stmt::AugAssign(cons) => Stmt::AugAssign(Foldable::fold(cons, folder)?),
|
Stmt::AugAssign(cons) => Stmt::AugAssign(Foldable::fold(cons, folder)?),
|
||||||
Stmt::AnnAssign(cons) => Stmt::AnnAssign(Foldable::fold(cons, folder)?),
|
Stmt::AnnAssign(cons) => Stmt::AnnAssign(Foldable::fold(cons, folder)?),
|
||||||
Stmt::For(cons) => Stmt::For(Foldable::fold(cons, folder)?),
|
Stmt::For(cons) => Stmt::For(Foldable::fold(cons, folder)?),
|
||||||
|
@ -697,6 +728,7 @@ pub fn fold_stmt_function_def<U, F: Fold<U> + ?Sized>(
|
||||||
decorator_list,
|
decorator_list,
|
||||||
returns,
|
returns,
|
||||||
type_comment,
|
type_comment,
|
||||||
|
type_params,
|
||||||
range,
|
range,
|
||||||
} = node;
|
} = node;
|
||||||
let context = folder.will_map_user(&range);
|
let context = folder.will_map_user(&range);
|
||||||
|
@ -707,6 +739,7 @@ pub fn fold_stmt_function_def<U, F: Fold<U> + ?Sized>(
|
||||||
let decorator_list = Foldable::fold(decorator_list, folder)?;
|
let decorator_list = Foldable::fold(decorator_list, folder)?;
|
||||||
let returns = Foldable::fold(returns, folder)?;
|
let returns = Foldable::fold(returns, folder)?;
|
||||||
let type_comment = Foldable::fold(type_comment, folder)?;
|
let type_comment = Foldable::fold(type_comment, folder)?;
|
||||||
|
let type_params = Foldable::fold(type_params, folder)?;
|
||||||
let range = folder.map_user(range, context)?;
|
let range = folder.map_user(range, context)?;
|
||||||
Ok(StmtFunctionDef {
|
Ok(StmtFunctionDef {
|
||||||
name,
|
name,
|
||||||
|
@ -715,6 +748,7 @@ pub fn fold_stmt_function_def<U, F: Fold<U> + ?Sized>(
|
||||||
decorator_list,
|
decorator_list,
|
||||||
returns,
|
returns,
|
||||||
type_comment,
|
type_comment,
|
||||||
|
type_params,
|
||||||
range,
|
range,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -738,6 +772,7 @@ pub fn fold_stmt_async_function_def<U, F: Fold<U> + ?Sized>(
|
||||||
decorator_list,
|
decorator_list,
|
||||||
returns,
|
returns,
|
||||||
type_comment,
|
type_comment,
|
||||||
|
type_params,
|
||||||
range,
|
range,
|
||||||
} = node;
|
} = node;
|
||||||
let context = folder.will_map_user(&range);
|
let context = folder.will_map_user(&range);
|
||||||
|
@ -748,6 +783,7 @@ pub fn fold_stmt_async_function_def<U, F: Fold<U> + ?Sized>(
|
||||||
let decorator_list = Foldable::fold(decorator_list, folder)?;
|
let decorator_list = Foldable::fold(decorator_list, folder)?;
|
||||||
let returns = Foldable::fold(returns, folder)?;
|
let returns = Foldable::fold(returns, folder)?;
|
||||||
let type_comment = Foldable::fold(type_comment, folder)?;
|
let type_comment = Foldable::fold(type_comment, folder)?;
|
||||||
|
let type_params = Foldable::fold(type_params, folder)?;
|
||||||
let range = folder.map_user(range, context)?;
|
let range = folder.map_user(range, context)?;
|
||||||
Ok(StmtAsyncFunctionDef {
|
Ok(StmtAsyncFunctionDef {
|
||||||
name,
|
name,
|
||||||
|
@ -756,6 +792,7 @@ pub fn fold_stmt_async_function_def<U, F: Fold<U> + ?Sized>(
|
||||||
decorator_list,
|
decorator_list,
|
||||||
returns,
|
returns,
|
||||||
type_comment,
|
type_comment,
|
||||||
|
type_params,
|
||||||
range,
|
range,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -778,6 +815,7 @@ pub fn fold_stmt_class_def<U, F: Fold<U> + ?Sized>(
|
||||||
keywords,
|
keywords,
|
||||||
body,
|
body,
|
||||||
decorator_list,
|
decorator_list,
|
||||||
|
type_params,
|
||||||
range,
|
range,
|
||||||
} = node;
|
} = node;
|
||||||
let context = folder.will_map_user(&range);
|
let context = folder.will_map_user(&range);
|
||||||
|
@ -787,6 +825,7 @@ pub fn fold_stmt_class_def<U, F: Fold<U> + ?Sized>(
|
||||||
let keywords = Foldable::fold(keywords, folder)?;
|
let keywords = Foldable::fold(keywords, folder)?;
|
||||||
let body = Foldable::fold(body, folder)?;
|
let body = Foldable::fold(body, folder)?;
|
||||||
let decorator_list = Foldable::fold(decorator_list, folder)?;
|
let decorator_list = Foldable::fold(decorator_list, folder)?;
|
||||||
|
let type_params = Foldable::fold(type_params, folder)?;
|
||||||
let range = folder.map_user(range, context)?;
|
let range = folder.map_user(range, context)?;
|
||||||
Ok(StmtClassDef {
|
Ok(StmtClassDef {
|
||||||
name,
|
name,
|
||||||
|
@ -794,6 +833,7 @@ pub fn fold_stmt_class_def<U, F: Fold<U> + ?Sized>(
|
||||||
keywords,
|
keywords,
|
||||||
body,
|
body,
|
||||||
decorator_list,
|
decorator_list,
|
||||||
|
type_params,
|
||||||
range,
|
range,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -869,6 +909,38 @@ pub fn fold_stmt_assign<U, F: Fold<U> + ?Sized>(
|
||||||
range,
|
range,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
impl<T, U> Foldable<T, U> for StmtTypeAlias<T> {
|
||||||
|
type Mapped = StmtTypeAlias<U>;
|
||||||
|
fn fold<F: Fold<T, TargetU = U> + ?Sized>(
|
||||||
|
self,
|
||||||
|
folder: &mut F,
|
||||||
|
) -> Result<Self::Mapped, F::Error> {
|
||||||
|
folder.fold_stmt_type_alias(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn fold_stmt_type_alias<U, F: Fold<U> + ?Sized>(
|
||||||
|
#[allow(unused)] folder: &mut F,
|
||||||
|
node: StmtTypeAlias<U>,
|
||||||
|
) -> Result<StmtTypeAlias<F::TargetU>, F::Error> {
|
||||||
|
let StmtTypeAlias {
|
||||||
|
name,
|
||||||
|
type_params,
|
||||||
|
value,
|
||||||
|
range,
|
||||||
|
} = node;
|
||||||
|
let context = folder.will_map_user(&range);
|
||||||
|
|
||||||
|
let name = Foldable::fold(name, folder)?;
|
||||||
|
let type_params = Foldable::fold(type_params, folder)?;
|
||||||
|
let value = Foldable::fold(value, folder)?;
|
||||||
|
let range = folder.map_user(range, context)?;
|
||||||
|
Ok(StmtTypeAlias {
|
||||||
|
name,
|
||||||
|
type_params,
|
||||||
|
value,
|
||||||
|
range,
|
||||||
|
})
|
||||||
|
}
|
||||||
impl<T, U> Foldable<T, U> for StmtAugAssign<T> {
|
impl<T, U> Foldable<T, U> for StmtAugAssign<T> {
|
||||||
type Mapped = StmtAugAssign<U>;
|
type Mapped = StmtAugAssign<U>;
|
||||||
fn fold<F: Fold<T, TargetU = U> + ?Sized>(
|
fn fold<F: Fold<T, TargetU = U> + ?Sized>(
|
||||||
|
@ -2791,6 +2863,87 @@ pub fn fold_type_ignore_type_ignore<U, F: Fold<U> + ?Sized>(
|
||||||
let range = folder.map_user_cfg(range, context)?;
|
let range = folder.map_user_cfg(range, context)?;
|
||||||
Ok(TypeIgnoreTypeIgnore { lineno, tag, range })
|
Ok(TypeIgnoreTypeIgnore { lineno, tag, range })
|
||||||
}
|
}
|
||||||
|
impl<T, U> Foldable<T, U> for TypeParam<T> {
|
||||||
|
type Mapped = TypeParam<U>;
|
||||||
|
fn fold<F: Fold<T, TargetU = U> + ?Sized>(
|
||||||
|
self,
|
||||||
|
folder: &mut F,
|
||||||
|
) -> Result<Self::Mapped, F::Error> {
|
||||||
|
folder.fold_type_param(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn fold_type_param<U, F: Fold<U> + ?Sized>(
|
||||||
|
#[allow(unused)] folder: &mut F,
|
||||||
|
node: TypeParam<U>,
|
||||||
|
) -> Result<TypeParam<F::TargetU>, F::Error> {
|
||||||
|
let folded = match node {
|
||||||
|
TypeParam::TypeVar(cons) => TypeParam::TypeVar(Foldable::fold(cons, folder)?),
|
||||||
|
TypeParam::ParamSpec(cons) => TypeParam::ParamSpec(Foldable::fold(cons, folder)?),
|
||||||
|
TypeParam::TypeVarTuple(cons) => TypeParam::TypeVarTuple(Foldable::fold(cons, folder)?),
|
||||||
|
};
|
||||||
|
Ok(folded)
|
||||||
|
}
|
||||||
|
impl<T, U> Foldable<T, U> for TypeParamTypeVar<T> {
|
||||||
|
type Mapped = TypeParamTypeVar<U>;
|
||||||
|
fn fold<F: Fold<T, TargetU = U> + ?Sized>(
|
||||||
|
self,
|
||||||
|
folder: &mut F,
|
||||||
|
) -> Result<Self::Mapped, F::Error> {
|
||||||
|
folder.fold_type_param_type_var(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn fold_type_param_type_var<U, F: Fold<U> + ?Sized>(
|
||||||
|
#[allow(unused)] folder: &mut F,
|
||||||
|
node: TypeParamTypeVar<U>,
|
||||||
|
) -> Result<TypeParamTypeVar<F::TargetU>, F::Error> {
|
||||||
|
let TypeParamTypeVar { name, bound, range } = node;
|
||||||
|
let context = folder.will_map_user(&range);
|
||||||
|
|
||||||
|
let name = Foldable::fold(name, folder)?;
|
||||||
|
let bound = Foldable::fold(bound, folder)?;
|
||||||
|
let range = folder.map_user(range, context)?;
|
||||||
|
Ok(TypeParamTypeVar { name, bound, range })
|
||||||
|
}
|
||||||
|
impl<T, U> Foldable<T, U> for TypeParamParamSpec<T> {
|
||||||
|
type Mapped = TypeParamParamSpec<U>;
|
||||||
|
fn fold<F: Fold<T, TargetU = U> + ?Sized>(
|
||||||
|
self,
|
||||||
|
folder: &mut F,
|
||||||
|
) -> Result<Self::Mapped, F::Error> {
|
||||||
|
folder.fold_type_param_param_spec(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn fold_type_param_param_spec<U, F: Fold<U> + ?Sized>(
|
||||||
|
#[allow(unused)] folder: &mut F,
|
||||||
|
node: TypeParamParamSpec<U>,
|
||||||
|
) -> Result<TypeParamParamSpec<F::TargetU>, F::Error> {
|
||||||
|
let TypeParamParamSpec { name, range } = node;
|
||||||
|
let context = folder.will_map_user(&range);
|
||||||
|
|
||||||
|
let name = Foldable::fold(name, folder)?;
|
||||||
|
let range = folder.map_user(range, context)?;
|
||||||
|
Ok(TypeParamParamSpec { name, range })
|
||||||
|
}
|
||||||
|
impl<T, U> Foldable<T, U> for TypeParamTypeVarTuple<T> {
|
||||||
|
type Mapped = TypeParamTypeVarTuple<U>;
|
||||||
|
fn fold<F: Fold<T, TargetU = U> + ?Sized>(
|
||||||
|
self,
|
||||||
|
folder: &mut F,
|
||||||
|
) -> Result<Self::Mapped, F::Error> {
|
||||||
|
folder.fold_type_param_type_var_tuple(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn fold_type_param_type_var_tuple<U, F: Fold<U> + ?Sized>(
|
||||||
|
#[allow(unused)] folder: &mut F,
|
||||||
|
node: TypeParamTypeVarTuple<U>,
|
||||||
|
) -> Result<TypeParamTypeVarTuple<F::TargetU>, F::Error> {
|
||||||
|
let TypeParamTypeVarTuple { name, range } = node;
|
||||||
|
let context = folder.will_map_user(&range);
|
||||||
|
|
||||||
|
let name = Foldable::fold(name, folder)?;
|
||||||
|
let range = folder.map_user(range, context)?;
|
||||||
|
Ok(TypeParamTypeVarTuple { name, range })
|
||||||
|
}
|
||||||
impl<T, U> Foldable<T, U> for ArgWithDefault<T> {
|
impl<T, U> Foldable<T, U> for ArgWithDefault<T> {
|
||||||
type Mapped = ArgWithDefault<U>;
|
type Mapped = ArgWithDefault<U>;
|
||||||
fn fold<F: Fold<T, TargetU = U> + ?Sized>(
|
fn fold<F: Fold<T, TargetU = U> + ?Sized>(
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
// File automatically generated by ast/asdl_rs.py.
|
// File automatically generated by ast/asdl_rs.py.
|
||||||
|
|
||||||
use crate::text_size::TextRange;
|
use crate::text_size::TextRange;
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq, is_macro::Is)]
|
||||||
#[derive(is_macro::Is)]
|
|
||||||
pub enum Ast<R = TextRange> {
|
pub enum Ast<R = TextRange> {
|
||||||
#[is(name = "module")]
|
#[is(name = "module")]
|
||||||
Mod(Mod<R>),
|
Mod(Mod<R>),
|
||||||
|
@ -23,6 +22,7 @@ pub enum Ast<R = TextRange> {
|
||||||
MatchCase(MatchCase<R>),
|
MatchCase(MatchCase<R>),
|
||||||
Pattern(Pattern<R>),
|
Pattern(Pattern<R>),
|
||||||
TypeIgnore(TypeIgnore<R>),
|
TypeIgnore(TypeIgnore<R>),
|
||||||
|
TypeParam(TypeParam<R>),
|
||||||
}
|
}
|
||||||
impl<R> Node for Ast<R> {
|
impl<R> Node for Ast<R> {
|
||||||
const NAME: &'static str = "AST";
|
const NAME: &'static str = "AST";
|
||||||
|
@ -137,6 +137,12 @@ impl<R> From<TypeIgnore<R>> for Ast<R> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<R> From<TypeParam<R>> for Ast<R> {
|
||||||
|
fn from(node: TypeParam<R>) -> Self {
|
||||||
|
Ast::TypeParam(node)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// See also [mod](https://docs.python.org/3/library/ast.html#ast.mod)
|
/// See also [mod](https://docs.python.org/3/library/ast.html#ast.mod)
|
||||||
#[derive(Clone, Debug, PartialEq, is_macro::Is)]
|
#[derive(Clone, Debug, PartialEq, is_macro::Is)]
|
||||||
pub enum Mod<R = TextRange> {
|
pub enum Mod<R = TextRange> {
|
||||||
|
@ -256,6 +262,8 @@ pub enum Stmt<R = TextRange> {
|
||||||
Delete(StmtDelete<R>),
|
Delete(StmtDelete<R>),
|
||||||
#[is(name = "assign_stmt")]
|
#[is(name = "assign_stmt")]
|
||||||
Assign(StmtAssign<R>),
|
Assign(StmtAssign<R>),
|
||||||
|
#[is(name = "type_alias_stmt")]
|
||||||
|
TypeAlias(StmtTypeAlias<R>),
|
||||||
#[is(name = "aug_assign_stmt")]
|
#[is(name = "aug_assign_stmt")]
|
||||||
AugAssign(StmtAugAssign<R>),
|
AugAssign(StmtAugAssign<R>),
|
||||||
#[is(name = "ann_assign_stmt")]
|
#[is(name = "ann_assign_stmt")]
|
||||||
|
@ -310,6 +318,7 @@ pub struct StmtFunctionDef<R = TextRange> {
|
||||||
pub decorator_list: Vec<Expr<R>>,
|
pub decorator_list: Vec<Expr<R>>,
|
||||||
pub returns: Option<Box<Expr<R>>>,
|
pub returns: Option<Box<Expr<R>>>,
|
||||||
pub type_comment: Option<String>,
|
pub type_comment: Option<String>,
|
||||||
|
pub type_params: Vec<TypeParam<R>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R> Node for StmtFunctionDef<R> {
|
impl<R> Node for StmtFunctionDef<R> {
|
||||||
|
@ -321,6 +330,7 @@ impl<R> Node for StmtFunctionDef<R> {
|
||||||
"decorator_list",
|
"decorator_list",
|
||||||
"returns",
|
"returns",
|
||||||
"type_comment",
|
"type_comment",
|
||||||
|
"type_params",
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
impl<R> From<StmtFunctionDef<R>> for Stmt<R> {
|
impl<R> From<StmtFunctionDef<R>> for Stmt<R> {
|
||||||
|
@ -344,6 +354,7 @@ pub struct StmtAsyncFunctionDef<R = TextRange> {
|
||||||
pub decorator_list: Vec<Expr<R>>,
|
pub decorator_list: Vec<Expr<R>>,
|
||||||
pub returns: Option<Box<Expr<R>>>,
|
pub returns: Option<Box<Expr<R>>>,
|
||||||
pub type_comment: Option<String>,
|
pub type_comment: Option<String>,
|
||||||
|
pub type_params: Vec<TypeParam<R>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R> Node for StmtAsyncFunctionDef<R> {
|
impl<R> Node for StmtAsyncFunctionDef<R> {
|
||||||
|
@ -355,6 +366,7 @@ impl<R> Node for StmtAsyncFunctionDef<R> {
|
||||||
"decorator_list",
|
"decorator_list",
|
||||||
"returns",
|
"returns",
|
||||||
"type_comment",
|
"type_comment",
|
||||||
|
"type_params",
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
impl<R> From<StmtAsyncFunctionDef<R>> for Stmt<R> {
|
impl<R> From<StmtAsyncFunctionDef<R>> for Stmt<R> {
|
||||||
|
@ -377,12 +389,19 @@ pub struct StmtClassDef<R = TextRange> {
|
||||||
pub keywords: Vec<Keyword<R>>,
|
pub keywords: Vec<Keyword<R>>,
|
||||||
pub body: Vec<Stmt<R>>,
|
pub body: Vec<Stmt<R>>,
|
||||||
pub decorator_list: Vec<Expr<R>>,
|
pub decorator_list: Vec<Expr<R>>,
|
||||||
|
pub type_params: Vec<TypeParam<R>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R> Node for StmtClassDef<R> {
|
impl<R> Node for StmtClassDef<R> {
|
||||||
const NAME: &'static str = "ClassDef";
|
const NAME: &'static str = "ClassDef";
|
||||||
const FIELD_NAMES: &'static [&'static str] =
|
const FIELD_NAMES: &'static [&'static str] = &[
|
||||||
&["name", "bases", "keywords", "body", "decorator_list"];
|
"name",
|
||||||
|
"bases",
|
||||||
|
"keywords",
|
||||||
|
"body",
|
||||||
|
"decorator_list",
|
||||||
|
"type_params",
|
||||||
|
];
|
||||||
}
|
}
|
||||||
impl<R> From<StmtClassDef<R>> for Stmt<R> {
|
impl<R> From<StmtClassDef<R>> for Stmt<R> {
|
||||||
fn from(payload: StmtClassDef<R>) -> Self {
|
fn from(payload: StmtClassDef<R>) -> Self {
|
||||||
|
@ -463,6 +482,30 @@ impl<R> From<StmtAssign<R>> for Ast<R> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// See also [TypeAlias](https://docs.python.org/3/library/ast.html#ast.TypeAlias)
|
||||||
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
pub struct StmtTypeAlias<R = TextRange> {
|
||||||
|
pub range: R,
|
||||||
|
pub name: Box<Expr<R>>,
|
||||||
|
pub type_params: Vec<TypeParam<R>>,
|
||||||
|
pub value: Box<Expr<R>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<R> Node for StmtTypeAlias<R> {
|
||||||
|
const NAME: &'static str = "TypeAlias";
|
||||||
|
const FIELD_NAMES: &'static [&'static str] = &["name", "type_params", "value"];
|
||||||
|
}
|
||||||
|
impl<R> From<StmtTypeAlias<R>> for Stmt<R> {
|
||||||
|
fn from(payload: StmtTypeAlias<R>) -> Self {
|
||||||
|
Stmt::TypeAlias(payload)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<R> From<StmtTypeAlias<R>> for Ast<R> {
|
||||||
|
fn from(payload: StmtTypeAlias<R>) -> Self {
|
||||||
|
Stmt::from(payload).into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// See also [AugAssign](https://docs.python.org/3/library/ast.html#ast.AugAssign)
|
/// See also [AugAssign](https://docs.python.org/3/library/ast.html#ast.AugAssign)
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct StmtAugAssign<R = TextRange> {
|
pub struct StmtAugAssign<R = TextRange> {
|
||||||
|
@ -3074,6 +3117,86 @@ impl<R> Node for TypeIgnore<R> {
|
||||||
const FIELD_NAMES: &'static [&'static str] = &[];
|
const FIELD_NAMES: &'static [&'static str] = &[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// See also [type_param](https://docs.python.org/3/library/ast.html#ast.type_param)
|
||||||
|
#[derive(Clone, Debug, PartialEq, is_macro::Is)]
|
||||||
|
pub enum TypeParam<R = TextRange> {
|
||||||
|
TypeVar(TypeParamTypeVar<R>),
|
||||||
|
ParamSpec(TypeParamParamSpec<R>),
|
||||||
|
TypeVarTuple(TypeParamTypeVarTuple<R>),
|
||||||
|
}
|
||||||
|
|
||||||
|
/// See also [TypeVar](https://docs.python.org/3/library/ast.html#ast.TypeVar)
|
||||||
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
pub struct TypeParamTypeVar<R = TextRange> {
|
||||||
|
pub range: R,
|
||||||
|
pub name: Identifier,
|
||||||
|
pub bound: Option<Box<Expr<R>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<R> Node for TypeParamTypeVar<R> {
|
||||||
|
const NAME: &'static str = "TypeVar";
|
||||||
|
const FIELD_NAMES: &'static [&'static str] = &["name", "bound"];
|
||||||
|
}
|
||||||
|
impl<R> From<TypeParamTypeVar<R>> for TypeParam<R> {
|
||||||
|
fn from(payload: TypeParamTypeVar<R>) -> Self {
|
||||||
|
TypeParam::TypeVar(payload)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<R> From<TypeParamTypeVar<R>> for Ast<R> {
|
||||||
|
fn from(payload: TypeParamTypeVar<R>) -> Self {
|
||||||
|
TypeParam::from(payload).into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// See also [ParamSpec](https://docs.python.org/3/library/ast.html#ast.ParamSpec)
|
||||||
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
pub struct TypeParamParamSpec<R = TextRange> {
|
||||||
|
pub range: R,
|
||||||
|
pub name: Identifier,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<R> Node for TypeParamParamSpec<R> {
|
||||||
|
const NAME: &'static str = "ParamSpec";
|
||||||
|
const FIELD_NAMES: &'static [&'static str] = &["name"];
|
||||||
|
}
|
||||||
|
impl<R> From<TypeParamParamSpec<R>> for TypeParam<R> {
|
||||||
|
fn from(payload: TypeParamParamSpec<R>) -> Self {
|
||||||
|
TypeParam::ParamSpec(payload)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<R> From<TypeParamParamSpec<R>> for Ast<R> {
|
||||||
|
fn from(payload: TypeParamParamSpec<R>) -> Self {
|
||||||
|
TypeParam::from(payload).into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// See also [TypeVarTuple](https://docs.python.org/3/library/ast.html#ast.TypeVarTuple)
|
||||||
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
pub struct TypeParamTypeVarTuple<R = TextRange> {
|
||||||
|
pub range: R,
|
||||||
|
pub name: Identifier,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<R> Node for TypeParamTypeVarTuple<R> {
|
||||||
|
const NAME: &'static str = "TypeVarTuple";
|
||||||
|
const FIELD_NAMES: &'static [&'static str] = &["name"];
|
||||||
|
}
|
||||||
|
impl<R> From<TypeParamTypeVarTuple<R>> for TypeParam<R> {
|
||||||
|
fn from(payload: TypeParamTypeVarTuple<R>) -> Self {
|
||||||
|
TypeParam::TypeVarTuple(payload)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<R> From<TypeParamTypeVarTuple<R>> for Ast<R> {
|
||||||
|
fn from(payload: TypeParamTypeVarTuple<R>) -> Self {
|
||||||
|
TypeParam::from(payload).into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<R> Node for TypeParam<R> {
|
||||||
|
const NAME: &'static str = "type_param";
|
||||||
|
const FIELD_NAMES: &'static [&'static str] = &[];
|
||||||
|
}
|
||||||
|
|
||||||
/// An alternative type of AST `arguments`. This is parser-friendly and human-friendly definition of function arguments.
|
/// An alternative type of AST `arguments`. This is parser-friendly and human-friendly definition of function arguments.
|
||||||
/// This form also has advantage to implement pre-order traverse.
|
/// This form also has advantage to implement pre-order traverse.
|
||||||
/// `defaults` and `kw_defaults` fields are removed and the default values are placed under each `arg_with_default` typed argument.
|
/// `defaults` and `kw_defaults` fields are removed and the default values are placed under each `arg_with_default` typed argument.
|
||||||
|
|
|
@ -171,6 +171,20 @@ impl LocatedMut for StmtAssign {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type StmtTypeAlias = crate::generic::StmtTypeAlias<SourceRange>;
|
||||||
|
|
||||||
|
impl Located for StmtTypeAlias {
|
||||||
|
fn range(&self) -> SourceRange {
|
||||||
|
self.range
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LocatedMut for StmtTypeAlias {
|
||||||
|
fn range_mut(&mut self) -> &mut SourceRange {
|
||||||
|
&mut self.range
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub type StmtAugAssign = crate::generic::StmtAugAssign<SourceRange>;
|
pub type StmtAugAssign = crate::generic::StmtAugAssign<SourceRange>;
|
||||||
|
|
||||||
impl Located for StmtAugAssign {
|
impl Located for StmtAugAssign {
|
||||||
|
@ -474,6 +488,7 @@ impl Located for Stmt {
|
||||||
Self::Return(node) => node.range(),
|
Self::Return(node) => node.range(),
|
||||||
Self::Delete(node) => node.range(),
|
Self::Delete(node) => node.range(),
|
||||||
Self::Assign(node) => node.range(),
|
Self::Assign(node) => node.range(),
|
||||||
|
Self::TypeAlias(node) => node.range(),
|
||||||
Self::AugAssign(node) => node.range(),
|
Self::AugAssign(node) => node.range(),
|
||||||
Self::AnnAssign(node) => node.range(),
|
Self::AnnAssign(node) => node.range(),
|
||||||
Self::For(node) => node.range(),
|
Self::For(node) => node.range(),
|
||||||
|
@ -508,6 +523,7 @@ impl LocatedMut for Stmt {
|
||||||
Self::Return(node) => node.range_mut(),
|
Self::Return(node) => node.range_mut(),
|
||||||
Self::Delete(node) => node.range_mut(),
|
Self::Delete(node) => node.range_mut(),
|
||||||
Self::Assign(node) => node.range_mut(),
|
Self::Assign(node) => node.range_mut(),
|
||||||
|
Self::TypeAlias(node) => node.range_mut(),
|
||||||
Self::AugAssign(node) => node.range_mut(),
|
Self::AugAssign(node) => node.range_mut(),
|
||||||
Self::AnnAssign(node) => node.range_mut(),
|
Self::AnnAssign(node) => node.range_mut(),
|
||||||
Self::For(node) => node.range_mut(),
|
Self::For(node) => node.range_mut(),
|
||||||
|
@ -1367,6 +1383,70 @@ impl LocatedMut for TypeIgnore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type TypeParam = crate::generic::TypeParam<SourceRange>;
|
||||||
|
|
||||||
|
pub type TypeParamTypeVar = crate::generic::TypeParamTypeVar<SourceRange>;
|
||||||
|
|
||||||
|
impl Located for TypeParamTypeVar {
|
||||||
|
fn range(&self) -> SourceRange {
|
||||||
|
self.range
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LocatedMut for TypeParamTypeVar {
|
||||||
|
fn range_mut(&mut self) -> &mut SourceRange {
|
||||||
|
&mut self.range
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type TypeParamParamSpec = crate::generic::TypeParamParamSpec<SourceRange>;
|
||||||
|
|
||||||
|
impl Located for TypeParamParamSpec {
|
||||||
|
fn range(&self) -> SourceRange {
|
||||||
|
self.range
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LocatedMut for TypeParamParamSpec {
|
||||||
|
fn range_mut(&mut self) -> &mut SourceRange {
|
||||||
|
&mut self.range
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type TypeParamTypeVarTuple = crate::generic::TypeParamTypeVarTuple<SourceRange>;
|
||||||
|
|
||||||
|
impl Located for TypeParamTypeVarTuple {
|
||||||
|
fn range(&self) -> SourceRange {
|
||||||
|
self.range
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LocatedMut for TypeParamTypeVarTuple {
|
||||||
|
fn range_mut(&mut self) -> &mut SourceRange {
|
||||||
|
&mut self.range
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Located for TypeParam {
|
||||||
|
fn range(&self) -> SourceRange {
|
||||||
|
match self {
|
||||||
|
Self::TypeVar(node) => node.range(),
|
||||||
|
Self::ParamSpec(node) => node.range(),
|
||||||
|
Self::TypeVarTuple(node) => node.range(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LocatedMut for TypeParam {
|
||||||
|
fn range_mut(&mut self) -> &mut SourceRange {
|
||||||
|
match self {
|
||||||
|
Self::TypeVar(node) => node.range_mut(),
|
||||||
|
Self::ParamSpec(node) => node.range_mut(),
|
||||||
|
Self::TypeVarTuple(node) => node.range_mut(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub type Arguments = crate::generic::Arguments<SourceRange>;
|
pub type Arguments = crate::generic::Arguments<SourceRange>;
|
||||||
|
|
||||||
#[cfg(feature = "all-nodes-with-ranges")]
|
#[cfg(feature = "all-nodes-with-ranges")]
|
||||||
|
|
|
@ -66,6 +66,11 @@ impl Ranged for crate::generic::StmtAssign<TextRange> {
|
||||||
self.range
|
self.range
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl Ranged for crate::generic::StmtTypeAlias<TextRange> {
|
||||||
|
fn range(&self) -> TextRange {
|
||||||
|
self.range
|
||||||
|
}
|
||||||
|
}
|
||||||
impl Ranged for crate::generic::StmtAugAssign<TextRange> {
|
impl Ranged for crate::generic::StmtAugAssign<TextRange> {
|
||||||
fn range(&self) -> TextRange {
|
fn range(&self) -> TextRange {
|
||||||
self.range
|
self.range
|
||||||
|
@ -180,6 +185,7 @@ impl Ranged for crate::Stmt {
|
||||||
Self::Return(node) => node.range(),
|
Self::Return(node) => node.range(),
|
||||||
Self::Delete(node) => node.range(),
|
Self::Delete(node) => node.range(),
|
||||||
Self::Assign(node) => node.range(),
|
Self::Assign(node) => node.range(),
|
||||||
|
Self::TypeAlias(node) => node.range(),
|
||||||
Self::AugAssign(node) => node.range(),
|
Self::AugAssign(node) => node.range(),
|
||||||
Self::AnnAssign(node) => node.range(),
|
Self::AnnAssign(node) => node.range(),
|
||||||
Self::For(node) => node.range(),
|
Self::For(node) => node.range(),
|
||||||
|
@ -496,6 +502,31 @@ impl Ranged for crate::TypeIgnore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Ranged for crate::generic::TypeParamTypeVar<TextRange> {
|
||||||
|
fn range(&self) -> TextRange {
|
||||||
|
self.range
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Ranged for crate::generic::TypeParamParamSpec<TextRange> {
|
||||||
|
fn range(&self) -> TextRange {
|
||||||
|
self.range
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Ranged for crate::generic::TypeParamTypeVarTuple<TextRange> {
|
||||||
|
fn range(&self) -> TextRange {
|
||||||
|
self.range
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Ranged for crate::TypeParam {
|
||||||
|
fn range(&self) -> TextRange {
|
||||||
|
match self {
|
||||||
|
Self::TypeVar(node) => node.range(),
|
||||||
|
Self::ParamSpec(node) => node.range(),
|
||||||
|
Self::TypeVarTuple(node) => node.range(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "all-nodes-with-ranges")]
|
#[cfg(feature = "all-nodes-with-ranges")]
|
||||||
impl Ranged for crate::generic::Arguments<TextRange> {
|
impl Ranged for crate::generic::Arguments<TextRange> {
|
||||||
fn range(&self) -> TextRange {
|
fn range(&self) -> TextRange {
|
||||||
|
|
|
@ -13,6 +13,7 @@ pub trait Visitor<R = crate::text_size::TextRange> {
|
||||||
Stmt::Return(data) => self.visit_stmt_return(data),
|
Stmt::Return(data) => self.visit_stmt_return(data),
|
||||||
Stmt::Delete(data) => self.visit_stmt_delete(data),
|
Stmt::Delete(data) => self.visit_stmt_delete(data),
|
||||||
Stmt::Assign(data) => self.visit_stmt_assign(data),
|
Stmt::Assign(data) => self.visit_stmt_assign(data),
|
||||||
|
Stmt::TypeAlias(data) => self.visit_stmt_type_alias(data),
|
||||||
Stmt::AugAssign(data) => self.visit_stmt_aug_assign(data),
|
Stmt::AugAssign(data) => self.visit_stmt_aug_assign(data),
|
||||||
Stmt::AnnAssign(data) => self.visit_stmt_ann_assign(data),
|
Stmt::AnnAssign(data) => self.visit_stmt_ann_assign(data),
|
||||||
Stmt::For(data) => self.visit_stmt_for(data),
|
Stmt::For(data) => self.visit_stmt_for(data),
|
||||||
|
@ -53,6 +54,9 @@ pub trait Visitor<R = crate::text_size::TextRange> {
|
||||||
if let Some(value) = node.returns {
|
if let Some(value) = node.returns {
|
||||||
self.visit_expr(*value);
|
self.visit_expr(*value);
|
||||||
}
|
}
|
||||||
|
for value in node.type_params {
|
||||||
|
self.visit_type_param(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fn visit_stmt_async_function_def(&mut self, node: StmtAsyncFunctionDef<R>) {
|
fn visit_stmt_async_function_def(&mut self, node: StmtAsyncFunctionDef<R>) {
|
||||||
self.generic_visit_stmt_async_function_def(node)
|
self.generic_visit_stmt_async_function_def(node)
|
||||||
|
@ -71,6 +75,9 @@ pub trait Visitor<R = crate::text_size::TextRange> {
|
||||||
if let Some(value) = node.returns {
|
if let Some(value) = node.returns {
|
||||||
self.visit_expr(*value);
|
self.visit_expr(*value);
|
||||||
}
|
}
|
||||||
|
for value in node.type_params {
|
||||||
|
self.visit_type_param(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fn visit_stmt_class_def(&mut self, node: StmtClassDef<R>) {
|
fn visit_stmt_class_def(&mut self, node: StmtClassDef<R>) {
|
||||||
self.generic_visit_stmt_class_def(node)
|
self.generic_visit_stmt_class_def(node)
|
||||||
|
@ -88,6 +95,9 @@ pub trait Visitor<R = crate::text_size::TextRange> {
|
||||||
for value in node.decorator_list {
|
for value in node.decorator_list {
|
||||||
self.visit_expr(value);
|
self.visit_expr(value);
|
||||||
}
|
}
|
||||||
|
for value in node.type_params {
|
||||||
|
self.visit_type_param(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fn visit_stmt_return(&mut self, node: StmtReturn<R>) {
|
fn visit_stmt_return(&mut self, node: StmtReturn<R>) {
|
||||||
self.generic_visit_stmt_return(node)
|
self.generic_visit_stmt_return(node)
|
||||||
|
@ -117,6 +127,22 @@ pub trait Visitor<R = crate::text_size::TextRange> {
|
||||||
self.visit_expr(*value);
|
self.visit_expr(*value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fn visit_stmt_type_alias(&mut self, node: StmtTypeAlias<R>) {
|
||||||
|
self.generic_visit_stmt_type_alias(node)
|
||||||
|
}
|
||||||
|
fn generic_visit_stmt_type_alias(&mut self, node: StmtTypeAlias<R>) {
|
||||||
|
{
|
||||||
|
let value = node.name;
|
||||||
|
self.visit_expr(*value);
|
||||||
|
}
|
||||||
|
for value in node.type_params {
|
||||||
|
self.visit_type_param(value);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
let value = node.value;
|
||||||
|
self.visit_expr(*value);
|
||||||
|
}
|
||||||
|
}
|
||||||
fn visit_stmt_aug_assign(&mut self, node: StmtAugAssign<R>) {
|
fn visit_stmt_aug_assign(&mut self, node: StmtAugAssign<R>) {
|
||||||
self.generic_visit_stmt_aug_assign(node)
|
self.generic_visit_stmt_aug_assign(node)
|
||||||
}
|
}
|
||||||
|
@ -810,4 +836,30 @@ pub trait Visitor<R = crate::text_size::TextRange> {
|
||||||
self.visit_pattern(value);
|
self.visit_pattern(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fn visit_type_param(&mut self, node: TypeParam<R>) {
|
||||||
|
self.generic_visit_type_param(node)
|
||||||
|
}
|
||||||
|
fn generic_visit_type_param(&mut self, node: TypeParam<R>) {
|
||||||
|
match node {
|
||||||
|
TypeParam::TypeVar(data) => self.visit_type_param_type_var(data),
|
||||||
|
TypeParam::ParamSpec(data) => self.visit_type_param_param_spec(data),
|
||||||
|
TypeParam::TypeVarTuple(data) => self.visit_type_param_type_var_tuple(data),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn visit_type_param_type_var(&mut self, node: TypeParamTypeVar<R>) {
|
||||||
|
self.generic_visit_type_param_type_var(node)
|
||||||
|
}
|
||||||
|
fn generic_visit_type_param_type_var(&mut self, node: TypeParamTypeVar<R>) {
|
||||||
|
if let Some(value) = node.bound {
|
||||||
|
self.visit_expr(*value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn visit_type_param_param_spec(&mut self, node: TypeParamParamSpec<R>) {
|
||||||
|
self.generic_visit_type_param_param_spec(node)
|
||||||
|
}
|
||||||
|
fn generic_visit_type_param_param_spec(&mut self, node: TypeParamParamSpec<R>) {}
|
||||||
|
fn visit_type_param_type_var_tuple(&mut self, node: TypeParamTypeVarTuple<R>) {
|
||||||
|
self.generic_visit_type_param_type_var_tuple(node)
|
||||||
|
}
|
||||||
|
fn generic_visit_type_param_type_var_tuple(&mut self, node: TypeParamTypeVarTuple<R>) {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,6 +138,29 @@ impl Parse for ast::StmtAssign {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Parse for ast::StmtTypeAlias {
|
||||||
|
fn lex_starts_at(
|
||||||
|
source: &str,
|
||||||
|
offset: TextSize,
|
||||||
|
) -> SoftKeywordTransformer<Lexer<std::str::Chars>> {
|
||||||
|
ast::Stmt::lex_starts_at(source, offset)
|
||||||
|
}
|
||||||
|
fn parse_tokens(
|
||||||
|
lxr: impl IntoIterator<Item = LexResult>,
|
||||||
|
source_path: &str,
|
||||||
|
) -> Result<Self, ParseError> {
|
||||||
|
let node = ast::Stmt::parse_tokens(lxr, source_path)?;
|
||||||
|
match node {
|
||||||
|
ast::Stmt::TypeAlias(node) => Ok(node),
|
||||||
|
node => Err(ParseError {
|
||||||
|
error: ParseErrorType::InvalidToken,
|
||||||
|
offset: node.range().start(),
|
||||||
|
source_path: source_path.to_owned(),
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Parse for ast::StmtAugAssign {
|
impl Parse for ast::StmtAugAssign {
|
||||||
fn lex_starts_at(
|
fn lex_starts_at(
|
||||||
source: &str,
|
source: &str,
|
||||||
|
|
27489
parser/src/python.rs
generated
27489
parser/src/python.rs
generated
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue