MCPcopy
hub / github.com/python/mypy / parse_version

Function parse_version

mypy/config_parser.py:37–58  ·  view source on GitHub ↗
(v: str | float)

Source from the content-addressed store, hash-verified

35
36
37def parse_version(v: str | float) -> tuple[int, int]:
38 m = re.match(r"\A(\d)\.(\d+)\Z", str(v))
39 if not m:
40 raise argparse.ArgumentTypeError(f"Invalid python version '{v}' (expected format: 'x.y')")
41 major, minor = int(m.group(1)), int(m.group(2))
42 if major == 2 and minor == 7:
43 pass # Error raised elsewhere
44 elif major == 3:
45 if minor < defaults.PYTHON3_VERSION_MIN[1]:
46 msg = "Python 3.{} is not supported (must be {}.{} or higher)".format(
47 minor, *defaults.PYTHON3_VERSION_MIN
48 )
49
50 if isinstance(v, float):
51 msg += ". You may need to put quotes around your Python version"
52
53 raise VersionTypeError(msg, fallback=defaults.PYTHON3_VERSION_MIN)
54 else:
55 raise argparse.ArgumentTypeError(
56 f"Python major version '{major}' out of range (must be 3)"
57 )
58 return major, minor
59
60
61def try_split(v: str | Sequence[str] | object, split_regex: str = ",") -> list[str]:

Callers

nothing calls this directly

Calls 6

strClass · 0.85
intClass · 0.85
isinstanceFunction · 0.85
VersionTypeErrorClass · 0.85
groupMethod · 0.80
formatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…