PEP suggestion: Uniform way to indicate Python language version

Chris Angelico rosuav at gmail.com
Mon Aug 22 11:33:59 EDT 2016


On Tue, Aug 23, 2016 at 12:29 AM, Random832 <random832 at fastmail.com> wrote:
> On Mon, Aug 22, 2016, at 09:21, Steve D'Aprano wrote:
>> Rather, you just use the features you rely on, document the minimum
>> supported version, and if somebody is silly enough to try running your
>> code
>> under Python 1.4, they'll get a SyntaxError or an exception when you try
>> to
>> do something that is not supported.
>
> Receiving a SyntaxError or whatever other exception, which provides no
> suggestion about how to actually fix the issue (install a later version
> of python / run with "python3" instead of "python"), is a bad user
> experience. It will continue to be a bad user experience when people are
> using features that only work on python 5.0 and later and other people
> are trying to run their scripts under python 4.0, so it not having
> existed all along is not a sufficient justification to not consider
> adding it,.

How bad, exactly? If you installed the program using a package manager
(apt, yum, brew, etc etc etc), there should be versioning directives
in that, just the same as if there's some particular feature of libc
or openssl or libjpeg that you need. And if you go to someone's web
site to download it, you should get told "This requires Python X.Y".

Sometimes, when there's a really common failure, you can toss in a
try/except, or even just a comment:

import tkinter # ImportError? You may need Python 3

which will then show up if something goes wrong. There are much, MUCH
better ways of solving this than trying to magically make older
Pythons, uhh.... uhh.... do what, exactly? Nobody's yet said what
ought to happen instead of SyntaxError/ImportError. Should the process
be terminated with an error message? Should a different exception be
raised (InsufficientVersionError) and a check added to the default
error handler so it displays differently (the way SystemExit does, or
rather doesn't display at all)? And above all, how is all this an
improvement over the status quo, which is either a
SyntaxError/ImportError straight away, or the ability to put a
straight-forward run-time check that does anything you like?

ChrisA



More information about the Python-list mailing list