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

Star operator without enclosing within parentheses #2496

Closed
thorwhalen opened this issue Sep 17, 2021 · 3 comments · Fixed by #2700
Closed

Star operator without enclosing within parentheses #2496

thorwhalen opened this issue Sep 17, 2021 · 3 comments · Fixed by #2700
Labels
T: bug Something isn't working

Comments

@thorwhalen
Copy link

Describe the bug

Returning a tuple containing star operator without enclosing with parentheses leads to a Cannot parse error.

Oh no! 💥 💔 💥

To Reproduce

def apply_to_last(input, func):
    *header, last = input
    return *header, func(last)

# which is valid code doing this:
assert apply_to_last([1,2,3], lambda x: x+10) == (1, 2, 13)

And try to blackify...

Expected behavior

I expect it to not choke.

There is a workaround -- enclosing in parentheses

def apply_to_last(input, func):
    *header, last = input
    return (*header, func(last))

But doing this makes the linter complain that "Remove redundant parentheses".

Environment (please complete the following information):

  • Version: axblack 20210720
  • MacOS 10.15.7
  • Python 3.8.6
@thorwhalen thorwhalen added the T: bug Something isn't working label Sep 17, 2021
@JelleZijlstra
Copy link
Collaborator

What python version do you have in your settings? This code is invalid in 3.6.

@thorwhalen
Copy link
Author

As in python --version right?

I ask because I mentioned it above:

3.8.6

@JelleZijlstra
Copy link
Collaborator

No, I mean Black's target-version setting. By default Black assumes your code is 3.6-compatible. Does it work if you limit your target-version to 3.8+.

We could perhaps autodetect this grammar change though and detect that the code is 3.8+.

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

Successfully merging a pull request may close this issue.

3 participants