Skip to content

Commit

Permalink
Fix TypeError when formatting with black 22.1.0+
Browse files Browse the repository at this point in the history
Resolve an TypeError issue caused by the return type of
`find_project_root` changing in black 22.1.0.
  • Loading branch information
wlcx committed Jan 30, 2022
1 parent 9b6e716 commit a27322f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion pylsp_black/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ def load_config(filename: str) -> Dict:

root = black.find_project_root((filename,))

pyproject_filename = root / "pyproject.toml"
# Black 22.1.0+ returns a tuple
if isinstance(root, tuple):
pyproject_filename = root[0] / "pyproject.toml"
else:
pyproject_filename = root / "pyproject.toml"

if not pyproject_filename.is_file():
if GLOBAL_CONFIG is not None and GLOBAL_CONFIG.exists():
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/target_version/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[tool.black]
target-version = ['py27']
target-version = ['py39']
2 changes: 1 addition & 1 deletion tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def test_load_config():
def test_load_config_target_version():
config = load_config(str(fixtures_dir / "target_version" / "example.py"))

assert config["target_version"] == {black.TargetVersion.PY27}
assert config["target_version"] == {black.TargetVersion.PY39}


def test_load_config_py36():
Expand Down

0 comments on commit a27322f

Please sign in to comment.