99from importlib .util import find_spec
1010from pathlib import Path
1111
12+ from ts_utils .metadata import get_oldest_supported_python , read_metadata
1213from ts_utils .paths import TEST_CASES_DIR , test_cases_path
1314from ts_utils .utils import colored
1415
1920_SUCCESS = colored ("Success" , "green" )
2021_SKIPPED = colored ("Skipped" , "yellow" )
2122_FAILED = colored ("Failed" , "red" )
22- # We're using the oldest fully supported version because it's the most likely to produce errors
23- # due to unsupported syntax, feature, or bug in a tool.
24- _PYTHON_VERSION = "3.9"
2523
2624
2725def _parse_jsonc (json_text : str ) -> str :
@@ -52,15 +50,16 @@ def main() -> None:
5250 )
5351 parser .add_argument (
5452 "--python-version" ,
55- default = _PYTHON_VERSION ,
53+ default = None ,
5654 choices = ("3.9" , "3.10" , "3.11" , "3.12" , "3.13" , "3.14" ),
57- help = "Target Python version for the test (default: %(default)s)." ,
55+ # We're using the oldest fully supported version because it's the most likely to produce errors
56+ # due to unsupported syntax, feature, or bug in a tool.
57+ help = "Target Python version for the test (defaults to oldest supported Python version)." ,
5858 )
5959 parser .add_argument ("path" , help = "Path of the stub to test in format <folder>/<stub>, from the root of the project." )
6060 args = parser .parse_args ()
6161 path = Path (args .path )
6262 run_stubtest : bool = args .run_stubtest
63- python_version : str = args .python_version
6463
6564 if len (path .parts ) != 2 :
6665 parser .error ("'path' argument should be in format <folder>/<stub>." )
@@ -69,6 +68,14 @@ def main() -> None:
6968 parser .error ("Only the 'stdlib' and 'stubs' folders are supported." )
7069 if not path .exists ():
7170 parser .error (f"{ path = } does not exist." )
71+
72+ if args .python_version :
73+ python_version : str = args .python_version
74+ elif folder in "stubs" :
75+ python_version = read_metadata (stub ).requires_python .version
76+ else :
77+ python_version = get_oldest_supported_python ()
78+
7279 stubtest_result : subprocess .CompletedProcess [bytes ] | None = None
7380 pytype_result : subprocess .CompletedProcess [bytes ] | None = None
7481
0 commit comments