Skip to content

Commit c1be01c

Browse files
authored
Merge pull request #30 from wlcx/fix-black-22.1.0
Fix TypeError when formatting with black 22.1.0+
2 parents 9b6e716 + a27322f commit c1be01c

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

pylsp_black/plugin.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ def load_config(filename: str) -> Dict:
9595

9696
root = black.find_project_root((filename,))
9797

98-
pyproject_filename = root / "pyproject.toml"
98+
# Black 22.1.0+ returns a tuple
99+
if isinstance(root, tuple):
100+
pyproject_filename = root[0] / "pyproject.toml"
101+
else:
102+
pyproject_filename = root / "pyproject.toml"
99103

100104
if not pyproject_filename.is_file():
101105
if GLOBAL_CONFIG is not None and GLOBAL_CONFIG.exists():
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[tool.black]
2-
target-version = ['py27']
2+
target-version = ['py39']

tests/test_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def test_load_config():
190190
def test_load_config_target_version():
191191
config = load_config(str(fixtures_dir / "target_version" / "example.py"))
192192

193-
assert config["target_version"] == {black.TargetVersion.PY27}
193+
assert config["target_version"] == {black.TargetVersion.PY39}
194194

195195

196196
def test_load_config_py36():

0 commit comments

Comments
 (0)