PEP suggestion: Uniform way to indicate Python language version

rocky rocky at gnu.org
Sun Aug 21 14:28:25 EDT 2016


The problem:

1. there are various code inspection tools that parse Python programs looking for style issues or whatnot. The deeper ones have to do a full parse of the python program. It would be helpful if there were a uniform way to indicate the Python language level used in Python source code.

2. I get a standalone python program that is not part of a package. vcprompt https://bitbucket.org/gward/vcprompt might be an example
It would be helpful if there were an easy way to know what language version of Python it assumes

Perl has something like called "use perl".  "use" is roughly equivalent to "import".

Possible solutions:

Do it the similar to "use perl". Here "perl" is a package that just tests the parameter given it. In Python such the code would look something like

File/module python30.py

   import sys
   assert sys.version >= (sys.version_info >= (3, 0))

The above works, but to reduce proliferation of packages it might be preferable to come up with some way to pass a version specification string similar to the specification strings allowed in setup.py

A metadata tag as a comment in a docstring or in a comment.
Preferably this would be given towards the top of the file to make it easier for tools to extract this information.

Thoughts?



More information about the Python-list mailing list