Warn users when Python 3.7 isn't supported

We started using the walrus operator so we dropped Python 3.7 support.
However, we used to be able to show this nicely to the user by having this check:

However, this isn’t shown to users of Python 3.7 because it already crashes due to SyntaxError on the walrus operator somewhere deeper.

So what would still be a user friendly way to tell users that 3.7 isn’t supported?

If your users are installing your software via wheel (or sdist)
packages, you can set the Requires-Python metadata to >=3.8 and then
users will get an error while trying to install your software on too
old of a version of the CPython interpreter.

1 Like

It’s a separate program that’s not distributed as wheel/sdist, so unfortunately that won’t work.

In that case, another option is to make what your users run a simple
script that works in Python 3.7 and checks to see if the version is
older than 3.8. That way it can express your error message at
runtime and only then imports and calls into your real module if
everything checks out.

The available solutions are fairly obvious, so long as you keep in
mind that there is no way for code which isn’t supported in a given
version of Python to provide a meaningful error controlled by you
when run under that version of Python.

Ensure that this version check is done in a file that doesn’t use, or import something that uses, the operator. The simplest way is to have the driver code do this check before importing the main functionality, and only doing that. For example, something like

import sys

def main(args):
    if sys.hexversion < 0x03080000:
        print("Sorry, requires Python 3.8 or above")
        print("You can read more at: https://sabnzbd.org/wiki/installation/install-off-modules")
    import _implementation

if __name__ == '__main__':