mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 06:11:43 +00:00
Use range: _
in lieu of range: _range
(#6296)
## Summary `range: _range` is slightly inconvenient because you can't use it multiple times within a single match, unlike `_`.
This commit is contained in:
parent
9e2bbf4beb
commit
9f3567dea6
9 changed files with 249 additions and 455 deletions
|
@ -727,7 +727,7 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
|
|||
ast::Expr::BoolOp(ast::ExprBoolOp {
|
||||
op,
|
||||
values,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::BoolOp(ExprBoolOp {
|
||||
op: (*op).into(),
|
||||
values: values.iter().map(Into::into).collect(),
|
||||
|
@ -735,7 +735,7 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
|
|||
ast::Expr::NamedExpr(ast::ExprNamedExpr {
|
||||
target,
|
||||
value,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::NamedExpr(ExprNamedExpr {
|
||||
target: target.into(),
|
||||
value: value.into(),
|
||||
|
@ -744,7 +744,7 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
|
|||
left,
|
||||
op,
|
||||
right,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::BinOp(ExprBinOp {
|
||||
left: left.into(),
|
||||
op: (*op).into(),
|
||||
|
@ -753,7 +753,7 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
|
|||
ast::Expr::UnaryOp(ast::ExprUnaryOp {
|
||||
op,
|
||||
operand,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::UnaryOp(ExprUnaryOp {
|
||||
op: (*op).into(),
|
||||
operand: operand.into(),
|
||||
|
@ -761,7 +761,7 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
|
|||
ast::Expr::Lambda(ast::ExprLambda {
|
||||
parameters,
|
||||
body,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::Lambda(ExprLambda {
|
||||
parameters: (parameters.as_ref()).into(),
|
||||
body: body.into(),
|
||||
|
@ -770,7 +770,7 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
|
|||
test,
|
||||
body,
|
||||
orelse,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::IfExp(ExprIfExp {
|
||||
test: test.into(),
|
||||
body: body.into(),
|
||||
|
@ -779,7 +779,7 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
|
|||
ast::Expr::Dict(ast::ExprDict {
|
||||
keys,
|
||||
values,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::Dict(ExprDict {
|
||||
keys: keys
|
||||
.iter()
|
||||
|
@ -787,16 +787,13 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
|
|||
.collect(),
|
||||
values: values.iter().map(Into::into).collect(),
|
||||
}),
|
||||
ast::Expr::Set(ast::ExprSet {
|
||||
elts,
|
||||
range: _range,
|
||||
}) => Self::Set(ExprSet {
|
||||
ast::Expr::Set(ast::ExprSet { elts, range: _ }) => Self::Set(ExprSet {
|
||||
elts: elts.iter().map(Into::into).collect(),
|
||||
}),
|
||||
ast::Expr::ListComp(ast::ExprListComp {
|
||||
elt,
|
||||
generators,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::ListComp(ExprListComp {
|
||||
elt: elt.into(),
|
||||
generators: generators.iter().map(Into::into).collect(),
|
||||
|
@ -804,7 +801,7 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
|
|||
ast::Expr::SetComp(ast::ExprSetComp {
|
||||
elt,
|
||||
generators,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::SetComp(ExprSetComp {
|
||||
elt: elt.into(),
|
||||
generators: generators.iter().map(Into::into).collect(),
|
||||
|
@ -813,7 +810,7 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
|
|||
key,
|
||||
value,
|
||||
generators,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::DictComp(ExprDictComp {
|
||||
key: key.into(),
|
||||
value: value.into(),
|
||||
|
@ -822,34 +819,27 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
|
|||
ast::Expr::GeneratorExp(ast::ExprGeneratorExp {
|
||||
elt,
|
||||
generators,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::GeneratorExp(ExprGeneratorExp {
|
||||
elt: elt.into(),
|
||||
generators: generators.iter().map(Into::into).collect(),
|
||||
}),
|
||||
ast::Expr::Await(ast::ExprAwait {
|
||||
value,
|
||||
range: _range,
|
||||
}) => Self::Await(ExprAwait {
|
||||
ast::Expr::Await(ast::ExprAwait { value, range: _ }) => Self::Await(ExprAwait {
|
||||
value: value.into(),
|
||||
}),
|
||||
ast::Expr::Yield(ast::ExprYield {
|
||||
value,
|
||||
range: _range,
|
||||
}) => Self::Yield(ExprYield {
|
||||
ast::Expr::Yield(ast::ExprYield { value, range: _ }) => Self::Yield(ExprYield {
|
||||
value: value.as_ref().map(Into::into),
|
||||
}),
|
||||
ast::Expr::YieldFrom(ast::ExprYieldFrom {
|
||||
value,
|
||||
range: _range,
|
||||
}) => Self::YieldFrom(ExprYieldFrom {
|
||||
value: value.into(),
|
||||
}),
|
||||
ast::Expr::YieldFrom(ast::ExprYieldFrom { value, range: _ }) => {
|
||||
Self::YieldFrom(ExprYieldFrom {
|
||||
value: value.into(),
|
||||
})
|
||||
}
|
||||
ast::Expr::Compare(ast::ExprCompare {
|
||||
left,
|
||||
ops,
|
||||
comparators,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::Compare(ExprCompare {
|
||||
left: left.into(),
|
||||
ops: ops.iter().copied().map(Into::into).collect(),
|
||||
|
@ -858,7 +848,7 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
|
|||
ast::Expr::Call(ast::ExprCall {
|
||||
func,
|
||||
arguments,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::Call(ExprCall {
|
||||
func: func.into(),
|
||||
arguments: arguments.into(),
|
||||
|
@ -868,23 +858,22 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
|
|||
conversion,
|
||||
debug_text,
|
||||
format_spec,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::FormattedValue(ExprFormattedValue {
|
||||
value: value.into(),
|
||||
conversion: *conversion,
|
||||
debug_text: debug_text.as_ref(),
|
||||
format_spec: format_spec.as_ref().map(Into::into),
|
||||
}),
|
||||
ast::Expr::JoinedStr(ast::ExprJoinedStr {
|
||||
values,
|
||||
range: _range,
|
||||
}) => Self::JoinedStr(ExprJoinedStr {
|
||||
values: values.iter().map(Into::into).collect(),
|
||||
}),
|
||||
ast::Expr::JoinedStr(ast::ExprJoinedStr { values, range: _ }) => {
|
||||
Self::JoinedStr(ExprJoinedStr {
|
||||
values: values.iter().map(Into::into).collect(),
|
||||
})
|
||||
}
|
||||
ast::Expr::Constant(ast::ExprConstant {
|
||||
value,
|
||||
kind,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::Constant(ExprConstant {
|
||||
value: value.into(),
|
||||
kind: kind.as_ref().map(String::as_str),
|
||||
|
@ -893,7 +882,7 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
|
|||
value,
|
||||
attr,
|
||||
ctx,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::Attribute(ExprAttribute {
|
||||
value: value.into(),
|
||||
attr: attr.as_str(),
|
||||
|
@ -903,7 +892,7 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
|
|||
value,
|
||||
slice,
|
||||
ctx,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::Subscript(ExprSubscript {
|
||||
value: value.into(),
|
||||
slice: slice.into(),
|
||||
|
@ -912,23 +901,19 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
|
|||
ast::Expr::Starred(ast::ExprStarred {
|
||||
value,
|
||||
ctx,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::Starred(ExprStarred {
|
||||
value: value.into(),
|
||||
ctx: ctx.into(),
|
||||
}),
|
||||
ast::Expr::Name(ast::ExprName {
|
||||
id,
|
||||
ctx,
|
||||
range: _range,
|
||||
}) => Self::Name(ExprName {
|
||||
ast::Expr::Name(ast::ExprName { id, ctx, range: _ }) => Self::Name(ExprName {
|
||||
id: id.as_str(),
|
||||
ctx: ctx.into(),
|
||||
}),
|
||||
ast::Expr::List(ast::ExprList {
|
||||
elts,
|
||||
ctx,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::List(ExprList {
|
||||
elts: elts.iter().map(Into::into).collect(),
|
||||
ctx: ctx.into(),
|
||||
|
@ -936,7 +921,7 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
|
|||
ast::Expr::Tuple(ast::ExprTuple {
|
||||
elts,
|
||||
ctx,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::Tuple(ExprTuple {
|
||||
elts: elts.iter().map(Into::into).collect(),
|
||||
ctx: ctx.into(),
|
||||
|
@ -945,7 +930,7 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
|
|||
lower,
|
||||
upper,
|
||||
step,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::Slice(ExprSlice {
|
||||
lower: lower.as_ref().map(Into::into),
|
||||
upper: upper.as_ref().map(Into::into),
|
||||
|
@ -954,7 +939,7 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
|
|||
ast::Expr::LineMagic(ast::ExprLineMagic {
|
||||
kind,
|
||||
value,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::LineMagic(ExprLineMagic {
|
||||
kind: *kind,
|
||||
value: value.as_str(),
|
||||
|
@ -1249,7 +1234,7 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
decorator_list,
|
||||
returns,
|
||||
type_params,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::FunctionDef(StmtFunctionDef {
|
||||
name: name.as_str(),
|
||||
parameters: parameters.into(),
|
||||
|
@ -1265,7 +1250,7 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
decorator_list,
|
||||
returns,
|
||||
type_params,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::AsyncFunctionDef(StmtAsyncFunctionDef {
|
||||
name: name.as_str(),
|
||||
parameters: parameters.into(),
|
||||
|
@ -1280,7 +1265,7 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
body,
|
||||
decorator_list,
|
||||
type_params,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::ClassDef(StmtClassDef {
|
||||
name: name.as_str(),
|
||||
arguments: arguments.as_ref().map(Into::into),
|
||||
|
@ -1288,20 +1273,14 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
decorator_list: decorator_list.iter().map(Into::into).collect(),
|
||||
type_params: type_params.as_ref().map(Into::into),
|
||||
}),
|
||||
ast::Stmt::Return(ast::StmtReturn {
|
||||
value,
|
||||
range: _range,
|
||||
}) => Self::Return(StmtReturn {
|
||||
ast::Stmt::Return(ast::StmtReturn { value, range: _ }) => Self::Return(StmtReturn {
|
||||
value: value.as_ref().map(Into::into),
|
||||
}),
|
||||
ast::Stmt::Delete(ast::StmtDelete {
|
||||
targets,
|
||||
range: _range,
|
||||
}) => Self::Delete(StmtDelete {
|
||||
ast::Stmt::Delete(ast::StmtDelete { targets, range: _ }) => Self::Delete(StmtDelete {
|
||||
targets: targets.iter().map(Into::into).collect(),
|
||||
}),
|
||||
ast::Stmt::TypeAlias(ast::StmtTypeAlias {
|
||||
range: _range,
|
||||
range: _,
|
||||
name,
|
||||
type_params,
|
||||
value,
|
||||
|
@ -1313,7 +1292,7 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
ast::Stmt::Assign(ast::StmtAssign {
|
||||
targets,
|
||||
value,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::Assign(StmtAssign {
|
||||
targets: targets.iter().map(Into::into).collect(),
|
||||
value: value.into(),
|
||||
|
@ -1322,7 +1301,7 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
target,
|
||||
op,
|
||||
value,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::AugAssign(StmtAugAssign {
|
||||
target: target.into(),
|
||||
op: (*op).into(),
|
||||
|
@ -1333,7 +1312,7 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
annotation,
|
||||
value,
|
||||
simple,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::AnnAssign(StmtAnnAssign {
|
||||
target: target.into(),
|
||||
annotation: annotation.into(),
|
||||
|
@ -1345,7 +1324,7 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
iter,
|
||||
body,
|
||||
orelse,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::For(StmtFor {
|
||||
target: target.into(),
|
||||
iter: iter.into(),
|
||||
|
@ -1357,7 +1336,7 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
iter,
|
||||
body,
|
||||
orelse,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::AsyncFor(StmtAsyncFor {
|
||||
target: target.into(),
|
||||
iter: iter.into(),
|
||||
|
@ -1368,7 +1347,7 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
test,
|
||||
body,
|
||||
orelse,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::While(StmtWhile {
|
||||
test: test.into(),
|
||||
body: body.iter().map(Into::into).collect(),
|
||||
|
@ -1378,7 +1357,7 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
test,
|
||||
body,
|
||||
elif_else_clauses,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::If(StmtIf {
|
||||
test: test.into(),
|
||||
body: body.iter().map(Into::into).collect(),
|
||||
|
@ -1387,7 +1366,7 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
ast::Stmt::With(ast::StmtWith {
|
||||
items,
|
||||
body,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::With(StmtWith {
|
||||
items: items.iter().map(Into::into).collect(),
|
||||
body: body.iter().map(Into::into).collect(),
|
||||
|
@ -1395,7 +1374,7 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
ast::Stmt::AsyncWith(ast::StmtAsyncWith {
|
||||
items,
|
||||
body,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::AsyncWith(StmtAsyncWith {
|
||||
items: items.iter().map(Into::into).collect(),
|
||||
body: body.iter().map(Into::into).collect(),
|
||||
|
@ -1403,7 +1382,7 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
ast::Stmt::Match(ast::StmtMatch {
|
||||
subject,
|
||||
cases,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::Match(StmtMatch {
|
||||
subject: subject.into(),
|
||||
cases: cases.iter().map(Into::into).collect(),
|
||||
|
@ -1411,7 +1390,7 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
ast::Stmt::Raise(ast::StmtRaise {
|
||||
exc,
|
||||
cause,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::Raise(StmtRaise {
|
||||
exc: exc.as_ref().map(Into::into),
|
||||
cause: cause.as_ref().map(Into::into),
|
||||
|
@ -1421,7 +1400,7 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
handlers,
|
||||
orelse,
|
||||
finalbody,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::Try(StmtTry {
|
||||
body: body.iter().map(Into::into).collect(),
|
||||
handlers: handlers.iter().map(Into::into).collect(),
|
||||
|
@ -1433,7 +1412,7 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
handlers,
|
||||
orelse,
|
||||
finalbody,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::TryStar(StmtTryStar {
|
||||
body: body.iter().map(Into::into).collect(),
|
||||
handlers: handlers.iter().map(Into::into).collect(),
|
||||
|
@ -1443,51 +1422,41 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
ast::Stmt::Assert(ast::StmtAssert {
|
||||
test,
|
||||
msg,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::Assert(StmtAssert {
|
||||
test: test.into(),
|
||||
msg: msg.as_ref().map(Into::into),
|
||||
}),
|
||||
ast::Stmt::Import(ast::StmtImport {
|
||||
names,
|
||||
range: _range,
|
||||
}) => Self::Import(StmtImport {
|
||||
ast::Stmt::Import(ast::StmtImport { names, range: _ }) => Self::Import(StmtImport {
|
||||
names: names.iter().map(Into::into).collect(),
|
||||
}),
|
||||
ast::Stmt::ImportFrom(ast::StmtImportFrom {
|
||||
module,
|
||||
names,
|
||||
level,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::ImportFrom(StmtImportFrom {
|
||||
module: module.as_deref(),
|
||||
names: names.iter().map(Into::into).collect(),
|
||||
level: *level,
|
||||
}),
|
||||
ast::Stmt::Global(ast::StmtGlobal {
|
||||
names,
|
||||
range: _range,
|
||||
}) => Self::Global(StmtGlobal {
|
||||
names: names.iter().map(ast::Identifier::as_str).collect(),
|
||||
}),
|
||||
ast::Stmt::Nonlocal(ast::StmtNonlocal {
|
||||
names,
|
||||
range: _range,
|
||||
}) => Self::Nonlocal(StmtNonlocal {
|
||||
ast::Stmt::Global(ast::StmtGlobal { names, range: _ }) => Self::Global(StmtGlobal {
|
||||
names: names.iter().map(ast::Identifier::as_str).collect(),
|
||||
}),
|
||||
ast::Stmt::Nonlocal(ast::StmtNonlocal { names, range: _ }) => {
|
||||
Self::Nonlocal(StmtNonlocal {
|
||||
names: names.iter().map(ast::Identifier::as_str).collect(),
|
||||
})
|
||||
}
|
||||
ast::Stmt::LineMagic(ast::StmtLineMagic {
|
||||
kind,
|
||||
value,
|
||||
range: _range,
|
||||
range: _,
|
||||
}) => Self::LineMagic(StmtLineMagic {
|
||||
kind: *kind,
|
||||
value: value.as_str(),
|
||||
}),
|
||||
ast::Stmt::Expr(ast::StmtExpr {
|
||||
value,
|
||||
range: _range,
|
||||
}) => Self::Expr(StmtExpr {
|
||||
ast::Stmt::Expr(ast::StmtExpr { value, range: _ }) => Self::Expr(StmtExpr {
|
||||
value: value.into(),
|
||||
}),
|
||||
ast::Stmt::Pass(_) => Self::Pass,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue