axiros/axblack

Formatter fails to run

CoatedMoose opened this issue · 6 comments

Describe the bug

A freshly installed axblack (pip install axblack==20220321) fails to run with an error patching _unicodefun from click. It seems between release 8.0.4 and 8.1.0 of click, that method was removed.

To Reproduce

  1. Install 20220321 of axblack fresh (with no additional version spec for click)
  2. Run black on any project

Expected behavior

Code to be formatted.

Environment (please complete the following information):

  • Version: 20220321
  • OS and Python version: Ubuntu 20.04.4 LTS, Python 3.8

Does this bug also happen on master? To answer this, you have two options:

Did not test this on master.

Additional context

Changing my formatter install command to the following resolves the issue:

pip install axblack==20200130 "click<8.1"
axgkl commented

Hi & thanks!

Removed that _unicodefun as well from patch_click => pip install axblack should work with newest click now.

=> can u verify and close, if so?

It seems that the newest version does run.

$ pip install --upgrade --upgrade-strategy eager axblack
# snip normal looking dependency resolution
Successfully installed axblack-20220330 click-8.1.2 regex-2022.3.15
$ black ./ --exclude migrations/
# snip large number of unexpected changes of """ -> '''

The new version changes all the double-quote block strings (""") strings to single-quote ('''), which the version I was previously using (20200130) was not doing. Is this expected with the newer version? Is it configurable?

axgkl commented

Can you detail what you mean here (example), triple quoted strings are still formatted to """:

/tmpblack --version                                                                 
black, version 20220330
/tmpcat r.py                                                                        
'''
mod doc

'''
def foo():
    '''func doc'''
    foo    = "bar"; baz= [ "bar"]
/tmpcat r.py| black -                                                               
"""
mod doc

"""


def foo():
    """func doc"""
    foo = 'bar'
    baz = ['bar']
reformatted -
All done! ✨ 🍰 ✨
1 file reformatted.

Previous behaviour we used:

$ cat simple_test.py


def a_method():
    long_string = """
        This is a long
        string for testing
    """
    print(long_string)
$ black --version
black, version 20200130
$ cat simple_test.py| black -
No Python files are present to be formatted. Nothing to do 😴

With a newer version of axblack

$ black --version
black, version 20220330
$ cat simple_test.py| black -
def a_method():
    long_string = '''
        This is a long
        string for testing
    '''
    print(long_string)
reformatted -
All done! ✨ 🍰 ✨
1 file reformatted.

The long_string variable has had it's quote type changed, where that was not the behaviour in previous versions.

axgkl commented

Ok, I see what you mean: The version of 2020 january 30 could not format on stdin (black -) but when you apply on the file you get in deed this:

~/repos/lc-python feat_devapp_open ⇡2 ?4 ❯ black --version                                                                            lc-python_py3.8
black, version 20200130
~/repos/lc-python feat_devapp_open ⇡2 ?4 ❯ cat a.py                                                                                   lc-python_py3.8
astring = "foo"

def a_method():
    long_string = """
        This is a long
        string for testing
    """
    print(long_string)
~/repos/lc-python feat_devapp_open ⇡2 ?4 ❯ black a.py                                                                                 lc-python_py3.8
reformatted a.py
All done! ✨ 🍰 ✨
1 file reformatted.
~/repos/lc-python feat_devapp_open ⇡2 ?4 ❯ cat a.py                                                                                   lc-python_py3.8
astring = 'foo'


def a_method():
    long_string = """
        This is a long
        string for testing
    """
    print(long_string)

Means: ALL triple quoted strings, docstrings or not, where turned to double apos.

While our documented style, since quite a while is:

2022-04-11__013

Double quotes ONLY for docstrings. Code only single quotes, triple quoted or not. I think the change followed a change the PSF/black version did also back then, once.

I cannot change it back to the old behaviour now (do find the current form also better but that is a matter of personal taste).

I would say, if you really want to keep double apo tripple quotes within your codebases, then nail the black version to 20200130 - which means, you have to nail the click version as well. Sorry for that.

axgkl commented

closing - reopen or send a PR for the cli flag.
thanks again for the bug report!