Skip to content

Commit 25746de

Browse files
author
Gaetano Guerriero
committed
black: propagate target_versions from pyproject.toml config
1 parent 2203597 commit 25746de

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

elpy/blackutil.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,25 @@ def fix_code(code, directory):
5151
line_length = black_config["line-length"]
5252
if "skip-string-normalization" in black_config:
5353
string_normalization = not black_config["skip-string-normalization"]
54+
if "target-version" in black_config:
55+
target_versions = {
56+
black.TargetVersion[v.upper()] for v in black_config["target-version"]
57+
}
58+
5459
try:
5560
if parse_version(black.__version__) < parse_version("19.0"):
5661
reformatted_source = black.format_file_contents(
57-
src_contents=code, line_length=line_length, fast=False)
62+
src_contents=code, line_length=line_length, fast=False
63+
)
5864
else:
5965
fm = black.FileMode(
6066
line_length=line_length,
61-
string_normalization=string_normalization)
67+
string_normalization=string_normalization,
68+
target_versions=target_versions,
69+
)
6270
reformatted_source = black.format_file_contents(
63-
src_contents=code, fast=False, mode=fm)
71+
src_contents=code, fast=False, mode=fm
72+
)
6473
return reformatted_source
6574
except black.NothingChanged:
6675
return code

0 commit comments

Comments
 (0)