There is no convention that I know of for specifying supported versions of Python in the Python source file. If you create a Python library and distribute it through PyPI (and pip ), you can add the package metadata, which indicates the versions of Python with which it is compatible.
For example, for my scandir, you can see on PyPI that it is (currently) marked as compatible with Python 2.6, 2.7, and 3.2-3.5. This metadata is in the classifiers key in the setup.py package:
setup( name='scandir',
If you do not release this as a PyPI package, one of the alternatives may be triggered by a warning when a module is imported on an earlier version of Python, stating that the FizzBuzz function is not supported in this version of Python.
import sys, warnings if sys.version_info < (3, 5): warnings.warn('The FizzBuzz feature is only supported on Python 3.5+')
All that has been said, personally, I am just simply simple: the document that the function X is only supported on Python 3.5+, and then if someone tries to use this function in an older version, just let it fail.
source share