-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bug] RUF010 autofix bug #4927
Comments
Interesting, thanks. Will take a look at these today. |
Anyone is welcome to beat me to it :) |
Having a quick look but can't replicate. Both running ruff 0.0.271 after installing it through pip and running: cargo run -p ruff_cli -- check --fix test.py --select RUF010 --no-cache on up to date main just fix the snippet. |
I'm able to repro by running on: (
f"Member of tuple mismatches type at index {i}. Expected {of_shape_i}. Got "
f"{repr(obj)} of type {type(obj)}.{additional_message}"
) I'm assuming that we're not matching properly against implicit concatenations. |
I think I have a fix for this. |
Yeah that triggers it here too. Let me know if you need an extra pair of hands on the fix. |
I'd appreciate it if you have time. What I was planning to do was artificially parenthesize the expression when passing to the LibCST parser: ❯ git diff HEAD
diff --git a/crates/ruff/src/rules/ruff/rules/explicit_f_string_type_conversion.rs b/crates/ruff/src/rules/ruff/rules/explicit_f_string_type_conversion.rs
index 18e93ab3c..f276b837b 100644
--- a/crates/ruff/src/rules/ruff/rules/explicit_f_string_type_conversion.rs
+++ b/crates/ruff/src/rules/ruff/rules/explicit_f_string_type_conversion.rs
@@ -1,11 +1,11 @@
use anyhow::{bail, Result};
use rustpython_parser::ast::{self, Expr, Ranged};
-use crate::autofix::codemods::CodegenStylist;
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::source_code::{Locator, Stylist};
+use crate::autofix::codemods::CodegenStylist;
use crate::checkers::ast::Checker;
use crate::cst::matchers::{
match_call_mut, match_expression, match_formatted_string, match_formatted_string_expression,
@@ -55,7 +55,8 @@ fn fix_explicit_f_string_type_conversion(
// Replace the call node with its argument and a conversion flag.
let range = expr.range();
let content = locator.slice(range);
- let mut expression = match_expression(content)?;
+ let parenthesized_content = format!("({})", content);
+ let mut expression = match_expression(&parenthesized_content)?;
let formatted_string = match_formatted_string(&mut expression)?; Right now, we're passing this literal, which isn't a valid expression (it has to be parenthesized): f"Member of tuple mismatches type at index {i}. Expected {of_shape_i}. Got "
f"{repr(obj)} of type {type(obj)}.{additional_message}" We then need to do two things:
|
I'll have a look, see how far I get |
On upgrading to 0.0.271, running
ruff --fix
is giving a lot of errors on trying to fix f strings. Here's an example string that triggers the error:And here's the full output, which references many more examples
The text was updated successfully, but these errors were encountered: