File tree 1 file changed +12
-15
lines changed
crates/ruff_linter/src/rules/pyupgrade/rules
1 file changed +12
-15
lines changed Original file line number Diff line number Diff line change @@ -198,28 +198,31 @@ pub(crate) fn native_literals(
198
198
checker. diagnostics . push ( diagnostic) ;
199
199
}
200
200
Some ( arg) => {
201
- let ( literal_expr, unary) = if let Some ( literal_expr) = arg. as_literal_expr ( ) {
202
- ( literal_expr, false )
201
+ let literal_expr = if let Some ( literal_expr) = arg. as_literal_expr ( ) {
202
+ // Skip implicit concatenated strings.
203
+ if literal_expr. is_implicit_concatenated ( ) {
204
+ return ;
205
+ } else {
206
+ literal_expr
207
+ }
203
208
} else if let Expr :: UnaryOp ( ast:: ExprUnaryOp {
204
209
op : UnaryOp :: UAdd | UnaryOp :: USub ,
205
210
operand,
206
211
..
207
212
} ) = arg
208
213
{
209
- if let Some ( literal_expr) = operand. as_literal_expr ( ) {
210
- ( literal_expr, true )
214
+ if let Some ( literal_expr) = operand
215
+ . as_literal_expr ( )
216
+ . filter ( |expr| matches ! ( expr, LiteralExpressionRef :: NumberLiteral ( _) ) )
217
+ {
218
+ literal_expr
211
219
} else {
212
220
return ;
213
221
}
214
222
} else {
215
223
return ;
216
224
} ;
217
225
218
- // Skip implicit string concatenations.
219
- if literal_expr. is_implicit_concatenated ( ) {
220
- return ;
221
- }
222
-
223
226
let Ok ( arg_literal_type) = LiteralType :: try_from ( literal_expr) else {
224
227
return ;
225
228
} ;
@@ -228,12 +231,6 @@ pub(crate) fn native_literals(
228
231
return ;
229
232
}
230
233
231
- if unary {
232
- if !matches ! ( literal_type, LiteralType :: Int | LiteralType :: Float ) {
233
- return ;
234
- }
235
- }
236
-
237
234
let arg_code = checker. locator ( ) . slice ( arg) ;
238
235
239
236
// Attribute access on an integer requires the integer to be parenthesized to disambiguate from a float
You can’t perform that action at this time.
0 commit comments