-
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
[flake8-pytest-style
] Add automatic fix for pytest-parametrize-values-wrong-type
(PT007
)
#10461
Conversation
Thanks for this!
So, if you want to do this, you can't use I'm fine to merge with the generator-based fix, though a locator-based fix tends to preserve more of this kind of trivia. Are you interested in trying it? |
Oh yes, I see it now that this approach deletes all comments. Thanks for pointing me to a place to check, I will try if I can do this. |
Yeah it's kind of a tradeoff. The generator is much easier (to program, and to get right), but much lower-fidelity. |
|
So, I have it now as a locator-based fix based of It also checks if a list has only 1 element and transforms The only thing is that |
And I have it now as a unsafe fix, but I think it should be safe to use in this approach. |
Oh, ruff-format seems to transform
Then maybe I need to remove the comma, because this disrupts the source formatting. |
You could, e.g., only remove the trailing comma if it immediately precedes the closing brace. |
Ah, I'm blind, I see it now. |
It doesn't look very elegant in my opinion, but it works. |
Thanks! I'll take a look now. I may tweak the locator usage a bit but it's generally what I was suggesting. |
@@ -79,5 +79,6 @@ def test_single_list_of_lists(param): | |||
|
|||
@pytest.mark.parametrize("a", [1, 2]) | |||
@pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) | |||
@pytest.mark.parametrize("d", [3,]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one bugfix: the PR was adding a trailing comma here, which led to ,,
flake8-pytest-style
] Add automatic fix for pytest-parametrize-values-wrong-type
(PT007
)
Summary
This adds automatic fixes for the
PT007
rule.I am currently reviewing and adding Ruff rules to Home Assistant. One rule is PT007, which has multiple hundred occurrences in the codebase, but no automatic fix, and this is not fun to do manually, especially because using Regexes are not really possible with this.
My knowledge of the Ruff codebase and Rust in general is not good and this is my first PR here, so I hope it is not too bad.
One thing where I need help is: How can I have the transformed code to be formatted automatically, instead of it being minimized as it does it now?
Test Plan
Using the existing fixtures and updated snapshots.