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

black adds trailing comma despite using --target-version py35 #759

Closed
bjoernricks opened this issue Mar 15, 2019 · 5 comments · Fixed by #763
Closed

black adds trailing comma despite using --target-version py35 #759

bjoernricks opened this issue Mar 15, 2019 · 5 comments · Fixed by #763
Assignees

Comments

@bjoernricks
Copy link

Hi,

black 19.3b0 adds trailing commas for function signatures containing * despite setting target version 3.5. This creates invalid code for python 3.5 which will raise a SyntaxError. Setting
target version to py34 or using the auto detection doesn't add a trailing comma in this case.

def foo_func(bar, *, lorem=None, ipsum=None, dolor=None, sit=None, amet=None, consectetur=None):
    print('lorem ipsum dolor sit amet')

running

> black --target-version py35 --line-length 80 foo.py

creates

def foo_func(
    bar,
    *,
    lorem=None,
    ipsum=None,
    dolor=None,
    sit=None,
    amet=None,
    consectetur=None,
):
    print("lorem ipsum dolor sit amet")

Operating system: Ubuntu 18.04
Python version: Python 3.5/3.6
Black version:

> black --version
black, version 19.3b0

Does also happen on master: yes

@JelleZijlstra
Copy link
Collaborator

Looks like we improperly merged two different syntax changes: f(**x,) (trailing comma in a call) first became legal in 3.5, but def f(**x,): pass (trailing comma in a definition) became legal only in 3.6. I'll try to disentangle the two in the code.

@bjoernricks
Copy link
Author

Thanks a lot!

dtantsur added a commit to dtantsur/python-zeroconf that referenced this issue May 20, 2019
Due to psf/black#759 black produces
code that is invalid Python 3.5 syntax even with --target-version py35.
This patch disables reformatting for this call (it doesn't seem to be
possible per line) until it's fixed.
dtantsur added a commit to dtantsur/python-zeroconf that referenced this issue May 20, 2019
Due to psf/black#759 black produces
code that is invalid Python 3.5 syntax even with --target-version py35.
This patch disables reformatting for this call (it doesn't seem to be
possible per line) until it's fixed.
jstasiak pushed a commit to python-zeroconf/python-zeroconf that referenced this issue May 22, 2019
This is a rebased and fixed version of PR #27, which also adds compatibility shim for ServiceInfo.address and does a proper deprecation for it.

* Present all addresses that are available.

* Add support for publishing multiple addresses.

* Add test for backwards compatibility.

* Provide proper deprecation of the "address" argument and field

* Raise deprecation warnings when address is used
* Add a compatibility property to avoid breaking existing code
  (based on suggestion by Bas Stottelaar in PR #27)
* Make addresses keyword-only, so that address can be eventually
  removed and replaced with it without breaking consumers
* Raise TypeError instead of an assertion on conflicting address
  and addresses

* Disable black on ServiceInfo.__init__ until black is fixed

Due to psf/black#759 black produces
code that is invalid Python 3.5 syntax even with --target-version py35.
This patch disables reformatting for this call (it doesn't seem to be
possible per line) until it's fixed.
@mikenerone
Copy link

Seems like there's a regression -I'm seeing this behavior with 20.8b1. It could be something more specific: my affected function has a return type annotation.

@ichard26
Copy link
Collaborator

ichard26 commented Nov 2, 2020

@mikenerone could you please post the bug-inducing code? Might be a case of #1356.

@mikenerone
Copy link

mikenerone commented Nov 3, 2020

@mikenerone could you please post the bug-inducing code? Might be a case of #1356.

I believe you're right. My triggering sample below closely resembles a case shown there.

class LongishClassNameToHelpTriggerTheBug:
    ...


def only_seems_to_trigger_bug_if_definition_is_long_enough_to_require_wrapping(
    *some_args: LongishClassNameToHelpTriggerTheBug
) -> LongishClassNameToHelpTriggerTheBug:
    pass

black 20.8b1 adds a trailing comma on the *some_args line, and the bug does not manifest if I remove the * first.

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

Successfully merging a pull request may close this issue.

4 participants