Commit 40e8b3a2 authored by Zsolt Dollenstein's avatar Zsolt Dollenstein Committed by Jelle Zijlstra
Browse files

[blackd] Support `py36`-style values in X-Python-Variant header (#979)

parent bd0ab3cb
Loading
Loading
Loading
Loading
+4 −0
Changes for blackd.py: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -129,7 +129,11 @@ def parse_python_variant_header(value: str) -> Tuple[bool, Set[black.TargetVersi
        for version in value.split(","):
            if version.startswith("py"):
                version = version[len("py") :]
            if "." in version:
                major_str, *rest = version.split(".")
            else:
                major_str = version[0]
                rest = [version[1:]] if len(version) > 1 else []
            try:
                major = int(major_str)
                if major not in (2, 3):
+8 −1
Changes for tests/test_black.py: 8 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -1624,18 +1624,25 @@ async def check(header_value: str, expected_status: int) -> None:
            response = await self.client.post(
                "/", data=code, headers={blackd.PYTHON_VARIANT_HEADER: header_value}
            )
            self.assertEqual(response.status, expected_status)
            self.assertEqual(
                response.status, expected_status, msg=await response.text()
            )

        await check("3.6", 200)
        await check("py3.6", 200)
        await check("3.6,3.7", 200)
        await check("3.6,py3.7", 200)
        await check("py36,py37", 200)
        await check("36", 200)
        await check("3.6.4", 200)

        await check("2", 204)
        await check("2.7", 204)
        await check("py2.7", 204)
        await check("3.4", 204)
        await check("py3.4", 204)
        await check("py34,py36", 204)
        await check("34", 204)

    @skip_if_exception("ClientOSError")
    @unittest.skipUnless(has_blackd_deps, "blackd's dependencies are not installed")