Repository: rupert/pyls-black

Issue:
Test failure with black version 21.04b
When updating black to version `21.04b` in nixos ( https://github.com/NixOS/nixpkgs/pull/120684 ) the tests for `pyls-black` fail (result at the end).

As part of https://github.com/psf/black/pull/1717 `PY36_VERSIONS` were moved from from `src/black/__init__.py` to `tests/test_black.py`.

The corresponding commit is https://github.com/psf/black/commit/6dddbd72414061cde9dd8ee72eac373b7fcf8b54 .

```
============================= test session starts ==============================
platform linux -- Python 3.8.9, pytest-6.2.3, py-1.10.0, pluggy-0.13.1
rootdir: /build/source
collected 16 items                                                             

tests/test_plugin.py .............F..                                    [100%]

=================================== FAILURES ===================================
____________________________ test_load_config_py36 _____________________________

    def test_load_config_py36():
>       config = load_config(str(fixtures_dir / "py36" / "example.py"))

tests/test_plugin.py:192:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

filename = '/build/source/tests/fixtures/py36/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"

        if not pyproject_filename.is_file():
            return defaults

        try:
            pyproject_toml = toml.load(str(pyproject_filename))
        except (toml.TomlDecodeError, OSError):
            return defaults

        file_config = pyproject_toml.get("tool", {}).get("black", {})
        file_config = {
            key.replace("--", "").replace("-", "_"): value
            for key, value in file_config.items()
        }

        config = {
            key: file_config.get(key, default_value)
            for key, default_value in defaults.items()
        }

        if file_config.get("target_version"):
            target_version = set(
                black.TargetVersion[x.upper()] for x in file_config["target_version"]
            )
        elif file_config.get("py36"):
>           target_version = black.PY36_VERSIONS
E           AttributeError: module 'black' has no attribute 'PY36_VERSIONS'

/nix/store/qqvpg72b33m1pxc5lzjfmx224jp2vrbx-python3.8-pyls-black-0.4.6/lib/python3.8/site-packages/pyls_black/plugin.py:100: AttributeError
=========================== short test summary info ============================
FAILED tests/test_plugin.py::test_load_config_py36 - AttributeError: module '...
========================= 1 failed, 15 passed in 0.66s =========================
```

Comments:

Patch:
diff --git a/pyls_black/plugin.py b/pyls_black/plugin.py
index 407802f..dc5d482 100644
--- a/pyls_black/plugin.py
+++ b/pyls_black/plugin.py
@@ -4,6 +4,8 @@ import black
 import toml
 from pyls import hookimpl
 
+_PY36_VERSIONS = {black.TargetVersion[v] for v in ["PY36", "PY37", "PY38", "PY39"]}
+
 
 @hookimpl(tryfirst=True)
 def pyls_format_document(document):
@@ -97,7 +99,7 @@ def load_config(filename: str) -> Dict:
             black.TargetVersion[x.upper()] for x in file_config["target_version"]
         )
     elif file_config.get("py36"):
-        target_version = black.PY36_VERSIONS
+        target_version = _PY36_VERSIONS
     else:
         target_version = set()
 


Test patch:
diff --git a/tests/test_plugin.py b/tests/test_plugin.py
index f943b16..e722dba 100644
--- a/tests/test_plugin.py
+++ b/tests/test_plugin.py
@@ -8,7 +8,12 @@ import pytest
 from pyls import uris
 from pyls.workspace import Document, Workspace
 
-from pyls_black.plugin import load_config, pyls_format_document, pyls_format_range
+from pyls_black.plugin import (
+    _PY36_VERSIONS,
+    load_config,
+    pyls_format_document,
+    pyls_format_range,
+)
 
 here = Path(__file__).parent
 fixtures_dir = here / "fixtures"
@@ -191,7 +196,7 @@ def test_load_config_target_version():
 def test_load_config_py36():
     config = load_config(str(fixtures_dir / "py36" / "example.py"))
 
-    assert config["target_version"] == black.PY36_VERSIONS
+    assert config["target_version"] == _PY36_VERSIONS
 
 
 def test_load_config_defaults():