mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
Remove unsupported type_comment
field
<!-- Thank you for contributing to Ruff! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary This PR removes the `type_comment` field which our parser doesn't support. <!-- What's the purpose of the change? What does it do, and why? --> ## Test Plan `cargo test` <!-- How was it tested? -->
This commit is contained in:
parent
4ad5903ef6
commit
7c7231db2e
54 changed files with 31 additions and 322 deletions
|
@ -376,7 +376,6 @@ impl<'a> From<&'a Box<ast::Arg>> for ComparableArg<'a> {
|
|||
pub struct ComparableArg<'a> {
|
||||
arg: &'a str,
|
||||
annotation: Option<Box<ComparableExpr<'a>>>,
|
||||
type_comment: Option<&'a str>,
|
||||
}
|
||||
|
||||
impl<'a> From<&'a ast::Arg> for ComparableArg<'a> {
|
||||
|
@ -384,7 +383,6 @@ impl<'a> From<&'a ast::Arg> for ComparableArg<'a> {
|
|||
Self {
|
||||
arg: arg.arg.as_str(),
|
||||
annotation: arg.annotation.as_ref().map(Into::into),
|
||||
type_comment: arg.type_comment.as_deref(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -955,7 +953,6 @@ pub struct StmtFunctionDef<'a> {
|
|||
decorator_list: Vec<ComparableDecorator<'a>>,
|
||||
type_params: Vec<ComparableTypeParam<'a>>,
|
||||
returns: Option<ComparableExpr<'a>>,
|
||||
type_comment: Option<&'a str>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
|
@ -966,7 +963,6 @@ pub struct StmtAsyncFunctionDef<'a> {
|
|||
decorator_list: Vec<ComparableDecorator<'a>>,
|
||||
type_params: Vec<ComparableTypeParam<'a>>,
|
||||
returns: Option<ComparableExpr<'a>>,
|
||||
type_comment: Option<&'a str>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
|
@ -1048,7 +1044,6 @@ pub struct TypeParamTypeVarTuple<'a> {
|
|||
pub struct StmtAssign<'a> {
|
||||
targets: Vec<ComparableExpr<'a>>,
|
||||
value: ComparableExpr<'a>,
|
||||
type_comment: Option<&'a str>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
|
@ -1072,7 +1067,6 @@ pub struct StmtFor<'a> {
|
|||
iter: ComparableExpr<'a>,
|
||||
body: Vec<ComparableStmt<'a>>,
|
||||
orelse: Vec<ComparableStmt<'a>>,
|
||||
type_comment: Option<&'a str>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
|
@ -1081,7 +1075,6 @@ pub struct StmtAsyncFor<'a> {
|
|||
iter: ComparableExpr<'a>,
|
||||
body: Vec<ComparableStmt<'a>>,
|
||||
orelse: Vec<ComparableStmt<'a>>,
|
||||
type_comment: Option<&'a str>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
|
@ -1102,14 +1095,12 @@ pub struct StmtIf<'a> {
|
|||
pub struct StmtWith<'a> {
|
||||
items: Vec<ComparableWithItem<'a>>,
|
||||
body: Vec<ComparableStmt<'a>>,
|
||||
type_comment: Option<&'a str>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
pub struct StmtAsyncWith<'a> {
|
||||
items: Vec<ComparableWithItem<'a>>,
|
||||
body: Vec<ComparableStmt<'a>>,
|
||||
type_comment: Option<&'a str>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
|
@ -1221,7 +1212,6 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
body,
|
||||
decorator_list,
|
||||
returns,
|
||||
type_comment,
|
||||
type_params,
|
||||
range: _range,
|
||||
}) => Self::FunctionDef(StmtFunctionDef {
|
||||
|
@ -1230,7 +1220,6 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
body: body.iter().map(Into::into).collect(),
|
||||
decorator_list: decorator_list.iter().map(Into::into).collect(),
|
||||
returns: returns.as_ref().map(Into::into),
|
||||
type_comment: type_comment.as_ref().map(String::as_str),
|
||||
type_params: type_params.iter().map(Into::into).collect(),
|
||||
}),
|
||||
ast::Stmt::AsyncFunctionDef(ast::StmtAsyncFunctionDef {
|
||||
|
@ -1239,7 +1228,6 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
body,
|
||||
decorator_list,
|
||||
returns,
|
||||
type_comment,
|
||||
type_params,
|
||||
range: _range,
|
||||
}) => Self::AsyncFunctionDef(StmtAsyncFunctionDef {
|
||||
|
@ -1248,7 +1236,6 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
body: body.iter().map(Into::into).collect(),
|
||||
decorator_list: decorator_list.iter().map(Into::into).collect(),
|
||||
returns: returns.as_ref().map(Into::into),
|
||||
type_comment: type_comment.as_ref().map(String::as_str),
|
||||
type_params: type_params.iter().map(Into::into).collect(),
|
||||
}),
|
||||
ast::Stmt::ClassDef(ast::StmtClassDef {
|
||||
|
@ -1292,12 +1279,10 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
ast::Stmt::Assign(ast::StmtAssign {
|
||||
targets,
|
||||
value,
|
||||
type_comment,
|
||||
range: _range,
|
||||
}) => Self::Assign(StmtAssign {
|
||||
targets: targets.iter().map(Into::into).collect(),
|
||||
value: value.into(),
|
||||
type_comment: type_comment.as_ref().map(String::as_str),
|
||||
}),
|
||||
ast::Stmt::AugAssign(ast::StmtAugAssign {
|
||||
target,
|
||||
|
@ -1326,28 +1311,24 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
iter,
|
||||
body,
|
||||
orelse,
|
||||
type_comment,
|
||||
range: _range,
|
||||
}) => Self::For(StmtFor {
|
||||
target: target.into(),
|
||||
iter: iter.into(),
|
||||
body: body.iter().map(Into::into).collect(),
|
||||
orelse: orelse.iter().map(Into::into).collect(),
|
||||
type_comment: type_comment.as_ref().map(String::as_str),
|
||||
}),
|
||||
ast::Stmt::AsyncFor(ast::StmtAsyncFor {
|
||||
target,
|
||||
iter,
|
||||
body,
|
||||
orelse,
|
||||
type_comment,
|
||||
range: _range,
|
||||
}) => Self::AsyncFor(StmtAsyncFor {
|
||||
target: target.into(),
|
||||
iter: iter.into(),
|
||||
body: body.iter().map(Into::into).collect(),
|
||||
orelse: orelse.iter().map(Into::into).collect(),
|
||||
type_comment: type_comment.as_ref().map(String::as_str),
|
||||
}),
|
||||
ast::Stmt::While(ast::StmtWhile {
|
||||
test,
|
||||
|
@ -1372,22 +1353,18 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
ast::Stmt::With(ast::StmtWith {
|
||||
items,
|
||||
body,
|
||||
type_comment,
|
||||
range: _range,
|
||||
}) => Self::With(StmtWith {
|
||||
items: items.iter().map(Into::into).collect(),
|
||||
body: body.iter().map(Into::into).collect(),
|
||||
type_comment: type_comment.as_ref().map(String::as_str),
|
||||
}),
|
||||
ast::Stmt::AsyncWith(ast::StmtAsyncWith {
|
||||
items,
|
||||
body,
|
||||
type_comment,
|
||||
range: _range,
|
||||
}) => Self::AsyncWith(StmtAsyncWith {
|
||||
items: items.iter().map(Into::into).collect(),
|
||||
body: body.iter().map(Into::into).collect(),
|
||||
type_comment: type_comment.as_ref().map(String::as_str),
|
||||
}),
|
||||
ast::Stmt::Match(ast::StmtMatch {
|
||||
subject,
|
||||
|
|
|
@ -79,13 +79,6 @@ impl<'a> AnyFunctionDefinition<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn type_comments(self) -> Option<&'a str> {
|
||||
match self {
|
||||
Self::FunctionDefinition(definition) => definition.type_comment.as_deref(),
|
||||
Self::AsyncFunctionDefinition(definition) => definition.type_comment.as_deref(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if this is [`Self::AsyncFunctionDefinition`]
|
||||
pub const fn is_async(self) -> bool {
|
||||
matches!(self, Self::AsyncFunctionDefinition(_))
|
||||
|
|
|
@ -156,7 +156,6 @@ pub struct StmtFunctionDef {
|
|||
pub decorator_list: Vec<Decorator>,
|
||||
pub returns: Option<Box<Expr>>,
|
||||
pub type_params: Vec<TypeParam>,
|
||||
pub type_comment: Option<String>,
|
||||
}
|
||||
|
||||
impl From<StmtFunctionDef> for Stmt {
|
||||
|
@ -175,7 +174,6 @@ pub struct StmtAsyncFunctionDef {
|
|||
pub decorator_list: Vec<Decorator>,
|
||||
pub returns: Option<Box<Expr>>,
|
||||
pub type_params: Vec<TypeParam>,
|
||||
pub type_comment: Option<String>,
|
||||
}
|
||||
|
||||
impl From<StmtAsyncFunctionDef> for Stmt {
|
||||
|
@ -249,7 +247,6 @@ pub struct StmtAssign {
|
|||
pub range: TextRange,
|
||||
pub targets: Vec<Expr>,
|
||||
pub value: Box<Expr>,
|
||||
pub type_comment: Option<String>,
|
||||
}
|
||||
|
||||
impl From<StmtAssign> for Stmt {
|
||||
|
@ -297,7 +294,6 @@ pub struct StmtFor {
|
|||
pub iter: Box<Expr>,
|
||||
pub body: Vec<Stmt>,
|
||||
pub orelse: Vec<Stmt>,
|
||||
pub type_comment: Option<String>,
|
||||
}
|
||||
|
||||
impl From<StmtFor> for Stmt {
|
||||
|
@ -314,7 +310,6 @@ pub struct StmtAsyncFor {
|
|||
pub iter: Box<Expr>,
|
||||
pub body: Vec<Stmt>,
|
||||
pub orelse: Vec<Stmt>,
|
||||
pub type_comment: Option<String>,
|
||||
}
|
||||
|
||||
impl From<StmtAsyncFor> for Stmt {
|
||||
|
@ -366,7 +361,6 @@ pub struct StmtWith {
|
|||
pub range: TextRange,
|
||||
pub items: Vec<WithItem>,
|
||||
pub body: Vec<Stmt>,
|
||||
pub type_comment: Option<String>,
|
||||
}
|
||||
|
||||
impl From<StmtWith> for Stmt {
|
||||
|
@ -381,7 +375,6 @@ pub struct StmtAsyncWith {
|
|||
pub range: TextRange,
|
||||
pub items: Vec<WithItem>,
|
||||
pub body: Vec<Stmt>,
|
||||
pub type_comment: Option<String>,
|
||||
}
|
||||
|
||||
impl From<StmtAsyncWith> for Stmt {
|
||||
|
@ -1877,7 +1870,6 @@ pub struct Arg {
|
|||
pub range: TextRange,
|
||||
pub arg: Identifier,
|
||||
pub annotation: Option<Box<Expr>>,
|
||||
pub type_comment: Option<String>,
|
||||
}
|
||||
|
||||
/// See also [keyword](https://docs.python.org/3/library/ast.html#ast.keyword)
|
||||
|
@ -3019,6 +3011,9 @@ mod size_assertions {
|
|||
use static_assertions::assert_eq_size;
|
||||
|
||||
assert_eq_size!(Stmt, [u8; 168]);
|
||||
assert_eq_size!(StmtFunctionDef, [u8; 128]);
|
||||
assert_eq_size!(StmtClassDef, [u8; 160]);
|
||||
assert_eq_size!(StmtTry, [u8; 104]);
|
||||
assert_eq_size!(Expr, [u8; 80]);
|
||||
assert_eq_size!(Constant, [u8; 32]);
|
||||
assert_eq_size!(Pattern, [u8; 96]);
|
||||
|
|
|
@ -239,7 +239,6 @@ where
|
|||
targets,
|
||||
value,
|
||||
range: _,
|
||||
type_comment: _,
|
||||
}) => {
|
||||
for expr in targets {
|
||||
visitor.visit_expr(expr);
|
||||
|
@ -320,13 +319,11 @@ where
|
|||
Stmt::With(ast::StmtWith {
|
||||
items,
|
||||
body,
|
||||
type_comment: _,
|
||||
range: _,
|
||||
})
|
||||
| Stmt::AsyncWith(ast::StmtAsyncWith {
|
||||
items,
|
||||
body,
|
||||
type_comment: _,
|
||||
range: _,
|
||||
}) => {
|
||||
for with_item in items {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue