X-Git-Url: https://git.madduck.net/etc/vim.git/blobdiff_plain/250ba7f04b300df284ba80cd4bb4122b45b41efb..6fe800933d8919436cabf40466ee462f49463814:/blackd.py?ds=inline diff --git a/blackd.py b/blackd.py index bfc410d..37fcec3 100644 --- a/blackd.py +++ b/blackd.py @@ -127,13 +127,13 @@ def parse_python_variant_header(value: str) -> Tuple[bool, Set[black.TargetVersi else: versions = set() for version in value.split(","): - tag = "cpy" - if version.startswith("cpy"): - version = version[len("cpy") :] - elif version.startswith("pypy"): - tag = "pypy" - version = version[len("pypy") :] - major_str, *rest = version.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): @@ -147,16 +147,12 @@ def parse_python_variant_header(value: str) -> Tuple[bool, Set[black.TargetVersi else: # Default to lowest supported minor version. minor = 7 if major == 2 else 3 - version_str = f"{tag.upper()}{major}{minor}" - # If PyPY is the same as CPython in some version, use - # the corresponding CPython version. - if tag == "pypy" and not hasattr(black.TargetVersion, version_str): - version_str = f"CPY{major}{minor}" + version_str = f"PY{major}{minor}" if major == 3 and not hasattr(black.TargetVersion, version_str): raise InvalidVariantHeader(f"3.{minor} is not supported") versions.add(black.TargetVersion[version_str]) except (KeyError, ValueError): - raise InvalidVariantHeader("expected e.g. '3.7', 'pypy3.5'") + raise InvalidVariantHeader("expected e.g. '3.7', 'py3.5'") return False, versions