Auto-format stops working after upgrade from 7 to 8
I recently upgraded from Wing 7 to Wing 8. Auto-formating using any of Black, PEP8 or Yapf no longer works.
I've checked the settings in both "Edit -> Preferences -> Editor -> Auto-formatting" and "Project -> Project Properties -> Options -> Auto-reformat". They both agree with "Auto-Reformat: Whole Files Before Save", and "Reformatter: Black".
I start Wing on Ubuntu 21.10 in a Python 3.10.2 virtual env. I have confirmed that all of black, pep8, yapf are installed and import properly in the Wing Python Shell under Py3.10.
Suggestions?
Comments
Could you please send us a bug report from Wing's Help menu or the end of the ide.log file from the Settings Directory listed in Wing's about box, right after trying and failing to do a reformat? That may show us what is failing. Thanks!
Thanks for the pointer to the log file.
The reformat fails because the version of "black" that the IDE invokes doesn't understand the 3.10.2 structural pattern matching construct. It gives this error: "error: cannot format /home/lars/.cache/wingpro8/tmp/3564325/tmpkuw8lchg.py: Cannot parse: 53:14: match the_other, len(the_other):".
If I invoke "black" from the command line in my venv, "black" succeeds in reformatting.
Further exploration of the log show that the IDE is invoking black with '--target-version', 'py39' parameters.
Have I missed a config parameter that is supposed to inform the IDE as to the version of Python I want?
I checked my "Project -> Environment" setup where I have the Python Executable set to "Activated Env: /home/lars/venv/py310/bin/activate"
I realize that there is another parallel problem going on that could stem from the same issue. Syntax highlighting in the ... (more)
I think black did not have --target-version py310 the last time I looked at this, but perhaps it's available now. This has been an annoying part of supporting black -- the fact that it lags behind Python and does weird things with what Python version it's checking for. We'll revisit this since maybe specifying --target-version at all is a mistake, but I seem to remember there was some reason it was needed.
That said, Wing runs black with /path/to/your/python -m black so it seems like it should be running the right one. Is the Python Shell in Wing showing that it's running Python 3.10?
In terms of Wing not understanding 3.10.2 patterning matching construct: It may be something we missed, and need to add support for, but I need to check with someone else here and can't right at the ... (more)
Yup, looks like this shipped in Black in Nov 2021... times does fly. We'll try to fix this soon to send the py310 flag. Or perhaps to not send any flag if that works now.