Skip to content

Excluding a Python version still adds classifiers for newer versions #732

Description

@redeboer

If a project excludes a Python version through excluded-python-versions, check-dev-files still adds Python version classifiers for every newer version that requires-python allows. Since Python 3.15 was added to the known versions, a project that excludes Python 3.14 therefore gets a Python 3.15 classifier, as well as a test-py315 Poe task.

This surfaced in ComPWA/tensorwaves#589, which has requires-python = ">=3.10" and excluded-python-versions = "3.14", because TensorFlow provides no wheels for Python 3.14. TensorFlow does not support Python 3.15 either, so the new classifier and test task are wrong. The repository can work around this by excluding "3.15" as well, but that has to be repeated for every new Python version.

Steps to reproduce

mkdir excluded-python-repro && cd excluded-python-repro
git init -q
mkdir tests && touch tests/__init__.py
cat > pyproject.toml <<'EOF'
[project]
classifiers = [
    "Programming Language :: Python :: 3.12",
    "Programming Language :: Python :: 3.13",
]
name = "my-package"
requires-python = ">=3.12"
version = "0.0.0"

[tool.compwa.policy]
dev-python-version = "3.13"

[tool.compwa.policy.python]
excluded-python-versions = "3.14"
EOF
cat > .pre-commit-config.yaml <<'EOF'
repos:
  - repo: https://github.com/ComPWA/policy
    rev: 236312689a32ad00fdef6d738e80eb38e8687dbb
    hooks:
      - id: check-dev-files
EOF
git add -A
prek run check-dev-files --all-files

The hook reports "Updated Python version classifiers" and adds "Programming Language :: Python :: 3.15" to the classifiers.

Cause

_update_python_version_classifiers() derives the classifiers from requires-python with _get_allowed_versions(), which only removes the excluded versions themselves. Every version newer than an excluded one is still listed if it satisfies requires-python.

Possible fix

A Python version is usually excluded because a dependency does not support it yet, and such a dependency will not support newer versions either. Possible solutions:

  • Exclude every version newer than the latest excluded version as well, so that excluded-python-versions = "3.14" acts as an upper bound until the exclusion is removed.
  • Only add a newer version than an excluded one if its classifier is already listed, so that a project can still opt in by hand.

In both cases, the derived test tasks and CI test matrix should follow the classifiers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐛 BugSomething isn't working

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions