Skip to content
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

Request: autofix for EM102 with msg #4103

Closed
jamesbraza opened this issue Apr 25, 2023 · 5 comments · Fixed by #4123
Closed

Request: autofix for EM102 with msg #4103

jamesbraza opened this issue Apr 25, 2023 · 5 comments · Fixed by #4123
Assignees
Labels
fixes Related to suggested fixes for violations

Comments

@jamesbraza
Copy link
Contributor

some_string = "ruff"
raise ValueError(f"Hello {some_string}.")

Running with ruff==0.0.263:

> ruff --fixable=EM102 --fix --select=EM102 a.py
a.py:2:18: EM102 Exception must not use an f-string literal, assign to variable first
Found 1 error.

It would be nice if EM102 supported autofix with msg like the rule explanation so:

some_string = "ruff"
msg = f"Hello {some_string}."
raise ValueError(msg)
@charliermarsh charliermarsh added the fixes Related to suggested fixes for violations label Apr 25, 2023
@charliermarsh
Copy link
Member

👍 I think we should be able to support this.

@dhruvmanila
Copy link
Member

What if the msg variable is already defined in same or outer scope? Should we try different variable names or maybe a config option for the user to specify the variable name? In any case, this would be a AutofixKind::Sometimes.

@charliermarsh
Copy link
Member

I'd suggest just skipping the fix if msg is defined in the same scope or any parent scope (but not making the name configurable).

@dhruvmanila
Copy link
Member

I would like to work on this, will get my hands dirty with the autofix API :)

@charliermarsh
Copy link
Member

Rock on, thanks @dhruvmanila! (Know I owe you some responses in other PRs too.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixes Related to suggested fixes for violations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants