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

PT006 fix adds unneeded parenthesis #2918

Closed
frenck opened this issue Feb 15, 2023 · 7 comments · Fixed by #3955
Closed

PT006 fix adds unneeded parenthesis #2918

frenck opened this issue Feb 15, 2023 · 7 comments · Fixed by #3955
Labels
bug Something isn't working

Comments

@frenck
Copy link
Contributor

frenck commented Feb 15, 2023

PT006 seems to add additional parenthesis in case the string is already wrapped in a parenthesis to split it into multiple lines.

image

@pytest.mark.parametrize(
    (
        "create_backup_error, create_backup_calls, "
        "update_addon_error, update_addon_calls, "
        "error_message"
    ),
	[...]
)

Results in:

@pytest.mark.parametrize(
    (
        (
            "create_backup_error",
            "create_backup_calls",
            "update_addon_error",
            "update_addon_calls",
            "error_message",
        )
    ),
    [...]
)

Expected:

@pytest.mark.parametrize(
    (
        "create_backup_error",
        "create_backup_calls",
        "update_addon_error",
        "update_addon_calls",
        "error_message",
    ),
    [...]
)
@charliermarsh charliermarsh added the bug Something isn't working label Feb 15, 2023
@charliermarsh
Copy link
Member

Thanks :)

@charliermarsh
Copy link
Member

Ohh interesting, because the expression is itself parenthesized already. Hmm...

@dhruvmanila
Copy link
Member

So, I was looking at the recent commit (abaf0a1) and thought of a similar approach in solving this problem.

The indexer will collect all the ranges for a pair of parenthesis (( to )). Then, while trying to generate a fix for the above case, we'll check how many ranges does the string expression range belongs to. If the value is 2, we won't add the parenthesis otherwise we will.

I'm not sure if you've any other solution in mind so just thought to share this.

@dhruvmanila
Copy link
Member

Actually, I've a better solution in mind, will try to fix it by tonight.

@frenck
Copy link
Contributor Author

frenck commented Apr 13, 2023

Thanks, @dhruvmanila 👍

../Frenck

@charliermarsh
Copy link
Member

Another all-star contribution from @dhruvmanila :)

@dhruvmanila
Copy link
Member

Another all-star contribution from @dhruvmanila :)

Thanks for your kind words! Always happy to help wherever I can 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants