From c129ed439831fe8d8794df1a811ccdc20d79252e Mon Sep 17 00:00:00 2001 From: Raphael Fakhri <153192858+RaphaelFakhri@users.noreply.github.com> Date: Thu, 5 Nov 2026 08:32:10 +0000 Subject: [PATCH] Lint: Validate every version in the Python-Version header --- check-peps.py | 2 +- .../tests/pep_lint/test_headers.py | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 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": diff --git a/pep_sphinx_extensions/tests/pep_lint/test_headers.py b/pep_sphinx_extensions/tests/pep_lint/test_headers.py index 89ecd81052c..233ce552efd 100644 --- a/pep_sphinx_extensions/tests/pep_lint/test_headers.py +++ b/pep_sphinx_extensions/tests/pep_lint/test_headers.py @@ -382,3 +382,27 @@ def test_validate_python_version(line: str, expected_warnings: set): assert warnings == [], warnings assert found_warnings == expected_warnings + + +@pytest.mark.parametrize( + ("line", "expected_warnings"), + [ + ( + "3.12, 4.0", + ["Python-Version major part must be 1, 2, or 3: 4.0"], + ), + ( + "3.x, 3.01", + ["Python-Version minor part must not have leading zeros: 3.01"], + ), + ( + "2.7, 3.0.a", + ["Python-Version micro part must be numeric: 3.0.a"], + ), + ], +) +def test_validate_python_version_multiple(line: str, expected_warnings: list): + warnings = [ + warning for (_, warning) in check_peps._validate_python_version(1, line) + ] + assert warnings == expected_warnings, warnings