Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatibility with black 22.1.0 #40

Open
lfam opened this issue Jan 31, 2022 · 1 comment · May be fixed by #41
Open

Incompatibility with black 22.1.0 #40

lfam opened this issue Jan 31, 2022 · 1 comment · May be fixed by #41

Comments

@lfam
Copy link

lfam commented Jan 31, 2022

While testing the update to Black 22.1.0 in Guix, we noticed that this program seems to need some adjustments.

After building pyls-black, we run the test suite. Almost all of the tests fails like this:

filename = '/tmp/guix-build-python-pyls-black-0.4.7.drv-0/source/tests/fixtures/example.py'

    def load_config(filename: str) -> Dict:
        defaults = {
            "line_length": 88,
            "fast": False,
            "pyi": filename.endswith(".pyi"),
            "skip_string_normalization": False,
            "target_version": set(),
        }

        root = black.find_project_root((filename,))

>       pyproject_filename = root / "pyproject.toml"
E       TypeError: unsupported operand type(s) for /: 'tuple' and 'str'

pyls_black/plugin.py:76: TypeError
=========================== short test summary info ============================
FAILED tests/test_plugin.py::test_pylsp_format_document - TypeError: unsuppor...
FAILED tests/test_plugin.py::test_pyls_format_pyi_document - TypeError: unsup...
FAILED tests/test_plugin.py::test_pylsp_format_document_unchanged - TypeError...
FAILED tests/test_plugin.py::test_pyls_format_pyi_document_unchanged - TypeEr...
FAILED tests/test_plugin.py::test_pylsp_format_document_syntax_error - TypeEr...
FAILED tests/test_plugin.py::test_pylsp_format_document_with_config - TypeErr...
FAILED tests/test_plugin.py::test_pylsp_format_range[0-0-a = "hello"\n] - Typ...
FAILED tests/test_plugin.py::test_pylsp_format_range[1-1-b = 42\n] - TypeErro...
FAILED tests/test_plugin.py::test_pylsp_format_range[0-1-a = "hello"\nb = 42\n]
FAILED tests/test_plugin.py::test_pylsp_format_range_unchanged - TypeError: u...
FAILED tests/test_plugin.py::test_pylsp_format_range_syntax_error - TypeError...
FAILED tests/test_plugin.py::test_load_config - TypeError: unsupported operan...
FAILED tests/test_plugin.py::test_load_config_target_version - TypeError: uns...
FAILED tests/test_plugin.py::test_load_config_py36 - TypeError: unsupported o...
FAILED tests/test_plugin.py::test_load_config_defaults - TypeError: unsupport...
========================= 15 failed, 1 passed in 0.47s =========================

My colleague says this about it:

Black changed the return type for find_project_root in this version. It
now returns a tuple instead of a Path object. 

And we can compare the Black versions 21.12b0 and 22.1.0.

@idadzie
Copy link

idadzie commented Feb 4, 2022

@lfam I had my pull request already fired up and ready to go, but it turns out it's already been fixed, awaiting a merge. See sublimelsp/LSP-pylsp#68.

While we wait, you can manually edit the plugin file located at <cache directory>/Package Storage/LSP-pylsp/lib/python3.8/site-packages/pylsp_black/plugin.py

Replace line 76

pyproject_filename = root / "pyproject.toml"

With

try:
    pyproject_filename = root / "pyproject.toml"
except TypeError:
    _root, _ = root
    pyproject_filename = _root / "pyproject.toml"

idadzie added a commit to idadzie/pyls-black that referenced this issue Feb 4, 2022
Make changes to support black 22.1.0, which changed the return type
of 'find_project_root' to a tuple.

Resolves: rupert#40
@idadzie idadzie linked a pull request Feb 4, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants