Infer target version based on project metadata by stinodego · Pull Request #3219 · psf/black (original) (raw)

JelleZijlstra

felix-hilden

felix-hilden

JelleZijlstra

ichard26

ichard26

@scop scop mentioned this pull request

Jan 20, 2023

ichard26

@ichard26

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 ichard26 marked this pull request as ready for review

January 31, 2023 20:13

JelleZijlstra

kdeldycke added a commit to kdeldycke/repomatic that referenced this pull request

Feb 2, 2023

@kdeldycke

gertvdijk added a commit to gertvdijk/purepythonmilter that referenced this pull request

Feb 27, 2023

@gertvdijk

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 jayqi mentioned this pull request

Oct 9, 2023

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 }})