In case we want to check if our code is compatible with a specific version of Python, we can get help from the library vermin.
Vermin is a library that detects the minimum Python version to run code.
As the documentation says:
“It functions by parsing Python code into an abstract syntax tree (AST), which it traverses and matches against internal dictionaries with 184 rules divided into 40 modules, 123 classes/functions/constants members of modules, and 21 kwargs of functions. Including looking for v2/v3
print expr and
"..".format(..), imports (
from X import Y,
from X import *), and function calls wrt. name and kwargs.”
Here you can find some usage examples, which come from the github repo:
% ./vermin Vermin 0.2.2 Usage: ./vermin [options] <python source files and folders..> Options: -q Quite mode. It only prints the final versions verdict. -v.. Verbosity level 1 to 2. -v shows less than -vv but more than no verbosity. -i Ignore incompatible version warnings. -p=X Use X concurrent processes to analyze files (defaults to all cores = 8). -d Dump AST node visits. % ./vermin -q vermin.py Minimum required versions: 2.7, 3.0 % ./vermin.py -v examples Detecting python files.. Analyzing 6 files using 8 processes.. /path/to/examples/formatv2.py 2.7, 3.2 /path/to/examples/argparse.py 2.7, 3.0 /path/to/examples/formatv3.py 2.0, 3.0 /path/to/examples/printv3.py !2, 3.4 /path/to/examples/abc.py /path/to/examples/unknown.py Minimum required versions: !2, 3.4
When it yields
!3 it means that it explicitly cannot run on that version