From 2a3884c24d42e201b749db4812c6fe4ead9152a0 Mon Sep 17 00:00:00 2001 From: dhairya05 Date: Mon, 9 Nov 2026 01:33:29 +0530 Subject: [PATCH 1/2] Do not abandon Python-Version validation at the first two-segment version _validate_python_version loops over the comma-separated versions in the header, but the "no micro part" branch used return rather than continue. Because it is a generator, that ended the whole validation instead of moving to the next version, so everything after the first X.Y version went unchecked: _validate_python_version(1, "3.0, 3.a") -> no warnings _validate_python_version(1, "3.12, 4.0") -> no warnings _validate_python_version(1, "3.11, 3.x.1") -> no warnings _validate_python_version(1, "3.9, 3.09") -> no warnings Two-segment versions are the overwhelming majority, so in practice only the first entry of a Python-Version header was ever validated. The checks all still existed; they were simply unreachable. An AST sweep for return inside a loop in a generator turns up one other hit, _validate_discussions_to, where the return is deliberate: it suppresses the catch-all error after a matching suffix. That one is left alone. --- check-peps.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check-peps.py b/check-peps.py index 20931c85a7e..43633ade9bd 100755 --- a/check-peps.py +++ b/check-peps.py @@ -398,7 +398,7 @@ def _validate_python_version(line_num: int, line: str) -> MessageIterator: yield line_num, f"Python-Version minor part must not have leading zeros: {version}" if micro == "": - return + continue if minor == "x": yield line_num, f"Python-Version micro part must be empty if minor part is 'x': {version}" elif micro[0] == "0": From 60ebe78b06a8b1c37d1f4fb520f875a708f4f064 Mon Sep 17 00:00:00 2001 From: dhairya05 Date: Mon, 9 Nov 2026 01:37:12 +0530 Subject: [PATCH 2/2] Test that every Python-Version entry is validated Five of these seven cases fail without the previous commit, because validation stopped at the first version without a micro part. The existing test_validate_python_version builds its expected messages from the whole line, so it can only describe single-version headers; this covers lists. --- .../tests/pep_lint/test_headers.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/pep_sphinx_extensions/tests/pep_lint/test_headers.py b/pep_sphinx_extensions/tests/pep_lint/test_headers.py index 89ecd81052c..49bb793ed68 100644 --- a/pep_sphinx_extensions/tests/pep_lint/test_headers.py +++ b/pep_sphinx_extensions/tests/pep_lint/test_headers.py @@ -382,3 +382,41 @@ def test_validate_python_version(line: str, expected_warnings: set): assert warnings == [], warnings assert found_warnings == expected_warnings + + +@pytest.mark.parametrize( + ("line", "expected_warnings"), + [ + # Every version in the header must be validated, not just the first. + # A version without a micro part used to end validation early. + ("3.0, 3.a", ["Python-Version minor part must be numeric: 3.a"]), + ("3.12, 4.0", ["Python-Version major part must be 1, 2, or 3: 4.0"]), + ( + "3.11, 3.x.1", + ["Python-Version micro part must be empty if minor part is 'x': 3.x.1"], + ), + ( + "3.9, 3.09", + ["Python-Version minor part must not have leading zeros: 3.09"], + ), + ( + "3.a, 4.b", + [ + "Python-Version minor part must be numeric: 3.a", + "Python-Version major part must be 1, 2, or 3: 4.b", + "Python-Version minor part must be numeric: 4.b", + ], + ), + # valid lists stay silent + ("3.0, 3.1, 3.14", []), + ("1.5.2, 2.7.18, 3.13.1", []), + ], + # call str() on each parameterised value in the test ID. + ids=str, +) +def test_validate_python_version_all_versions(line: str, expected_warnings: list): + warnings = [ + warning for (_, warning) in check_peps._validate_python_version(1, line) + ] + + assert warnings == expected_warnings, warnings