MCPcopy
hub / github.com/psf/black / parse_python_variant_header

Function parse_python_variant_header

src/blackd/__init__.py:297–327  ·  view source on GitHub ↗
(value: str)

Source from the content-addressed store, hash-verified

295
296
297def parse_python_variant_header(value: str) -> tuple[bool, set[black.TargetVersion]]:
298 if value == "pyi":
299 return True, set()
300 else:
301 versions = set()
302 for version in value.split(","):
303 if version.startswith("py"):
304 version = version[len("py") :]
305 if "." in version:
306 major_str, *rest = version.split(".")
307 else:
308 major_str = version[0]
309 rest = [version[1:]] if len(version) > 1 else []
310 try:
311 major = int(major_str)
312 if major not in (2, 3):
313 raise InvalidVariantHeader("major version must be 2 or 3")
314 if len(rest) > 0:
315 minor = int(rest[0])
316 if major == 2:
317 raise InvalidVariantHeader("Python 2 is not supported")
318 else:
319 # Default to lowest supported minor version.
320 minor = 7 if major == 2 else 3
321 version_str = f"PY{major}{minor}"
322 if major == 3 and not hasattr(black.TargetVersion, version_str):
323 raise InvalidVariantHeader(f"3.{minor} is not supported")
324 versions.add(black.TargetVersion[version_str])
325 except (KeyError, ValueError):
326 raise InvalidVariantHeader("expected e.g. '3.7', 'py3.5'") from None
327 return False, versions
328
329
330def patched_main() -> None:

Callers 1

parse_modeFunction · 0.85

Calls 1

Tested by

no test coverage detected