grantjenks / blue

The slightly less uncompromising Python code formatter.
https://blue.readthedocs.io/
Other
387 stars 21 forks source link

Support Python 3.10 features, especially match, request #59

Closed deeppunster closed 2 years ago

deeppunster commented 2 years ago

Currently blue (version 0.7.0) supports most features of Python 3.10 via black (version 21.7.b0), but not the match statement. Black version 21.12b0 apparently does (see black issue #2662. However, running blue with that version of black produces this error:

  $ blue src
  Traceback (most recent call last):
    File ".../venv/bin/blue", line 8, in <module>
      sys.exit(main())
    File ".../venv/lib/python3.10/site-packages/blue/__init__.py", line 385, in main
      assert config_param.name == 'config'
  AssertionError

Apparently, blue does not allow the option --target-version py310 nor the equivalent to be set in the pyproject.toml file (tools.black ...). Version info for current version of blue:

$ poetry show blue
name         : blue
version      : 0.7.0
description  : Blue -- Some folks like black but I prefer blue.

dependencies
 - black 21.7b0
 - flake8 3.8.4

Given that blue only patches black and that black does not consider version 21.12b0 to fully support match statements, is it premature to ask that blue can allow the interim version of black to be used with it?

grantjenks commented 2 years ago

It’s our goal to stay current with Black as new Python features are supported. Thanks for pointing out the issue. Could you share a snippet of code that black currently formats but blue does not?

deeppunster commented 2 years ago

Certainly. Here is a match statement that black will handle if "--target-version py310" is specified:

order = 1

match order:
    case 1:
        print("Matched number one")
    case 2:
        print("Matched number two")
    case _:
        print("No match")

And the output is:

Matched number one
deeppunster commented 2 years ago

Hi Grant,

Certainly. Here is a match statement that black will handle if”|--target-version py310|“ is specified:

|order = 1 match order: case 1: print("Matched number one") case 2: print("Matched number two") case _: print("No match") And the output is: |

|Matched number one |

HTH,

Travis

P. S. I added this code to the issue already.


Travis Risner

On 1/10/22 10:45 AM, Grant Jenks wrote:

It’s our goal to stay current with Black as newPython features are supported. Thanks for pointing out theissue. Could you share a snippet of code that black currentlyformats but blue does not?

— Reply to this email directly, view it on GitHub https://github.com/grantjenks/blue/issues/59#issuecomment-1009010058, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE3HZPL7M74QXZIXPCN4OSDUVL5KFANCNFSM5LQLZ3JQ. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.MessageID: @.***>

deeppunster commented 2 years ago

Oh, this works with black 21.12b0 or later.

chrisguillory commented 2 years ago

Is there any update on this? Perhaps there's a workaround available? We are on Python 3.10 and would like to use the new match statement /w blue. Thanks!

grantjenks commented 2 years ago

I believe #67 brought in support for Python 3.10 and the match statement. If you want, you can try formatting with HEAD and seeing how the diffs look.

Fyi @warsaw who was also going to check diffs.

chrisguillory commented 2 years ago

Thanks! We are using https://github.com/grantjenks/blue/pull/67 successfully and our diffs look good. Any idea when this new version might be released? (for now we install blue from commit hash).

warsaw commented 2 years ago

Thanks for the confirmation @chrisguillory - I'll do some quick checks myself and tag a new release. Automation should take it from there.

warsaw commented 2 years ago

LGTM