MCPcopy Create free account
hub / github.com/psf/black / parse_python_variant_header

Function parse_python_variant_header

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

Source from the content-addressed store, hash-verified

184
185
186def parse_python_variant_header(value: str) -> Tuple[bool, Set[black.TargetVersion]]:
187 if value == "pyi":
188 return True, set()
189 else:
190 versions = set()
191 for version in value.split(","):
192 if version.startswith("py"):
193 version = version[len("py") :]
194 if "." in version:
195 major_str, *rest = version.split(".")
196 else:
197 major_str = version[0]
198 rest = [version[1:]] if len(version) > 1 else []
199 try:
200 major = int(major_str)
201 if major not in (2, 3):
202 raise InvalidVariantHeader("major version must be 2 or 3")
203 if len(rest) > 0:
204 minor = int(rest[0])
205 if major == 2:
206 raise InvalidVariantHeader("Python 2 is not supported")
207 else:
208 # Default to lowest supported minor version.
209 minor = 7 if major == 2 else 3
210 version_str = f"PY{major}{minor}"
211 if major == 3 and not hasattr(black.TargetVersion, version_str):
212 raise InvalidVariantHeader(f"3.{minor} is not supported")
213 versions.add(black.TargetVersion[version_str])
214 except (KeyError, ValueError):
215 raise InvalidVariantHeader("expected e.g. '3.7', 'py3.5'") from None
216 return False, versions
217
218
219def patched_main() -> None:

Callers 1

handleFunction · 0.85

Calls 1

Tested by

no test coverage detected