Infer target version based on project metadata by stinodego · Pull Request #3219 · psf/black (original) (raw)
scop mentioned this pull request
Say you're attrs and you don't configure target-version. Previously Black would default to trying every single grammar it has, including the 3.10 grammar. With this PR, now target-version is configured for you effectively so now get_grammars() is more selective in which grammars it returns. If any target versions don't support the match statement, the 3.10 grammar won't be tried.
And while in theory a 3.7+ project shoudn't be using 3.10 features, attrs has a test file which uses match (which fails to parse because the 3.10 grammar isn't selected). To avoid breaking attrs, get_grammars() will now return the 3.10 grammar as long as any the target versions support match.
The out() call was made redundant by an older PR that prints the configuration if --verbose is passed.
ichard26 marked this pull request as ready for review
kdeldycke added a commit to kdeldycke/repomatic that referenced this pull request
gertvdijk added a commit to gertvdijk/purepythonmilter that referenced this pull request
Since Black's 23.1.0 release it infers the target versions via the project metadata (python-requires). Verified that it detects this correctly:
$ black -v src
[...]
target_version: ['py310', 'py311']
[...]See psf/black#3219
This was referenced
Apr 4, 2023
This was referenced
Jun 27, 2023
jayqi mentioned this pull request
12 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})