black
black copied to clipboard
added python version to parse error message
Description
improve parsing error message to make sure users know which version it was run on (fixes #3294).
Checklist - did you ...
- [x] Add an entry in
CHANGES.md
if necessary? - [x] Add / update tests if necessary?
- [x] Add new / update outdated documentation?
diff-shades reports zero changes comparing this PR (fc39bca8199c8218da8d19b6744e3e0234816733) to main (d338de7f687e90e292d949d2acd301f59fe5cdf8).
I feel like this will create more user confusion:
% black --target-version py36 -c 'a++' a++ error: cannot format <string>: Cannot parse (python 3.0): 1:3: a++ % black --target-version py39 -c 'a++' a++ error: cannot format <string>: Cannot parse (python 3.7): 1:3: a++
Users are going to wonder why it says "3.0" or "3.7" when they never asked for that version.
ok, can you help me understand why we parse python 3.0
, when a user asks to parse py36
?
ok, can you help me understand why we parse
python 3.0
, when a user asks to parsepy36
?
We don't have separate grammars for every version. For py36 we use a grammar with version set to (3, 0).
ok, can you help me understand why we parse
python 3.0
, when a user asks to parsepy36
?We don't have separate grammars for every version. For py36 we use a grammar with version set to (3, 0).
ok, so do we have an access to the version that the user provided somewhere?
It's the target version, which gets passed as a command-line parameter and thence as an argument to main()
.
hey @JelleZijlstra @felix-hilden, i've made some changes, please let me know if this is helpful 😄
I'm still not enthusiastic about this:
- Hardcoding the list of versions is a little hacky and hard to maintain
- I'm afraid the error message may still be confusing for users, but don't have a better suggestion
I'm still not enthusiastic about this:
- Hardcoding the list of versions is a little hacky and hard to maintain
- I'm afraid the error message may still be confusing for users, but don't have a better suggestion
- i've used the same hard-coding that is used by the parser, since there weren't any constants/functions which can be used to do that. that can be refactored of course.
- i think users are smart enough to understand what a range of numbers is, we're all programmers here...
feel free to close this if you're not interested