Howdy! Sorry you're having trouble. To expedite your experience,
provide some basics for me:
Operating system: Whatever
Python version: Whatever
Black version: 19.x
Does also happen on master: Yes
I was migrating from 18.x and looking into target-version for the first time. Since --target-version takes a string, I intuitively went for this
[tool.black]
target-version = "py37"
and was greeted by a cryptic error:
Error: Invalid value for "-t" / "--target-version": invalid choice: p. (choose from py27, py33, py34, py35, py36, py37, py38)
I realised that I should provide a list instead after staring at it for a while (in retrospect I should read the docs first), but the message could be a lot friendlier IMO.
I can think of two options:
It's also a bit confusing that in the pyproject file it's a singular target-version vs. target-versions.
I'm guessing that on the command line it's happy to take something like black --target-version py36 --target-version py37 ..., and Click or whatever is configured to jam them all into a set, which might only have a single item.
Tack an "s" on the key that's looked up in the settings file, or does that asymmetry hurt even more? :stuck_out_tongue:
Note that
[tool.black]
target-version = ["py37"]
pyproject.toml is in your version control and you use pre-commit, pre-commit will stash the changes to pyproject.toml, rolling back to the bad version, and then black will continue to fail with an error. Use git commit --no-verify to bypass pre-commit without disabling it.The problem here is that on the command line, Click handles turning your one argument into a list automatically, but Black handles the pyproject.toml parsing itself, meaning that it expects the value to be a list already. I guess a reasonable solution would be to convert a string with a valid target-version to a list before handing it off back to the main function.
EDIT: This should just be closed since Black will complain if target-version isn't a list because of PR https://github.com/psf/black/pull/1284
Most helpful comment
Note that
pyproject.tomlis in your version control and you usepre-commit, pre-commit will stash the changes to pyproject.toml, rolling back to the bad version, and then black will continue to fail with an error. Usegit commit --no-verifyto bypass pre-commit without disabling it.