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

UP007 adds parentheses when using --fix --unsafe-fixes and the Union has more than two types #8599

Closed
Lassii- opened this issue Nov 10, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@Lassii-
Copy link

Lassii- commented Nov 10, 2023

Ruff seems to add unnecessary parentheses when automatically fixing UP007 related errors.

test.py:

from typing import Union

def sample(a: Union[str, int, list]):
    print(a)

The ruff command used:

ruff check --select UP007 --target-version py311 --fix --unsafe-fixes test.py

test.py after being modified by Ruff:

from typing import Union

def sample(a: str | (int | list)):
    print(a)

Based on https://docs.python.org/3.11/library/stdtypes.html#union-type

from typing import Union

def sample(a: str | int | list):
    print(a)

would be okay unless I'm missing something?

@zanieb zanieb added the bug Something isn't working label Nov 10, 2023
@zanieb
Copy link
Member

zanieb commented Nov 10, 2023

Thanks for reporting. This seems reasonable to fix, although I do not know why it is that way in the first place.

@charliermarsh
Copy link
Member

I believe this was fixed in #8610.

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

No branches or pull requests

3 participants