MCPcopy Index your code
hub / github.com/python/mypy / load_stdlib_py_versions

Function load_stdlib_py_versions

mypy/modulefinder.py:972–998  ·  view source on GitHub ↗

Return dict with minimum and maximum Python versions of stdlib modules. The contents look like {..., 'secrets': ((3, 6), None), 'symbol': ((2, 7), (3, 9)), ...} None means there is no maximum version.

(custom_typeshed_dir: str | None)

Source from the content-addressed store, hash-verified

970
971
972def load_stdlib_py_versions(custom_typeshed_dir: str | None) -> StdlibVersions:
973 """Return dict with minimum and maximum Python versions of stdlib modules.
974
975 The contents look like
976 {..., 'secrets': ((3, 6), None), 'symbol': ((2, 7), (3, 9)), ...}
977
978 None means there is no maximum version.
979 """
980 typeshed_dir = custom_typeshed_dir or os_path_join(os.path.dirname(__file__), "typeshed")
981 stdlib_dir = os_path_join(typeshed_dir, "stdlib")
982 result = {}
983
984 versions_path = os_path_join(stdlib_dir, "VERSIONS")
985 assert os.path.isfile(versions_path), (custom_typeshed_dir, versions_path, __file__)
986 with open(versions_path) as f:
987 for line in f:
988 line = line.split("#")[0].strip()
989 if line == "":
990 continue
991 module, version_range = line.split(":")
992 versions = version_range.split("-")
993 min_version = parse_version(versions[0])
994 max_version = (
995 parse_version(versions[1]) if len(versions) >= 2 and versions[1].strip() else None
996 )
997 result[module] = min_version, max_version
998 return result
999
1000
1001def parse_version(version: str) -> tuple[int, int]:

Callers 1

__init__Method · 0.85

Calls 6

os_path_joinFunction · 0.90
lenFunction · 0.85
stripMethod · 0.80
splitMethod · 0.80
parse_versionFunction · 0.70
isfileMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…