Skip to content

Guide request: gracefully dropping support for older Python versions #450

Closed
@ncoghlan

Description

@ncoghlan

This guide has been written by @tonybaloney and can now be found here: https://packaging.python.org/guides/dropping-older-python-versions/


Talking to @tonybaloney about https://twitter.com/anthonypjshaw/status/970088412177776640, I discovered that our support for gracefully dropping support for older Python versions is currently better than I realised, but it's also far from obvious how to actually do it and the potential errors to avoid.

The key moving parts are:

The most conservative approach to implicitly pinning older clients to the last compatible release would be to release an alpha or development release that sets "Requires-Python: >= 3.6" (for example) in the metadata, and includes an import-time warning snippet like the one below, but doesn't actually require the new version yet:

_MINIMUM_SUPPORTED_VERSION = (3, 6, 0) # f-strings! Async generators!
if sys.version_info < _MINIMUM_SUPPORTED_VERSION:
    import warnings
    warnings.warn("This project no longer supports this version of Python, "
                  "but the release metadata indicating that has been ignored. "
                  "Please update to a newer installation client (e.g. pip 9+) and "
                  "ensure that any caching proxies in use support PEP 503's"
                  "`data-requires-python` link attribute.", FutureWarning)

(Using FutureWarning ensures that the message will be visible by default even on versions where DeprecationWarning is hidden by default)

This conservative approach has a few key benefits:

  1. It allows for opt-in testing of the metadata setting by folks running pip install --pre while others on recent pip versions will ignore it even if Requires-Python didn't get set correctly (since it's a pre-release)
  2. It means that folks with older deployment toolchains (even truly ancient ones that allow installation of pre-releases by default) will only get a (valid!) warning on stderr instead of a completely broken deployment.
  3. It means that if something does go wrong with setting Requires-Python in the metadata, you only end up with a pre-release that emits a spurious warning rather than one that's fundamentally broken, and can easily push a new version that sets that metadata correctly (since older clients should be updated to versions that default to ignoring pre-releases).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions