Tool to determine what lowest version of Python required?

后端 未结 3 2034
春和景丽
春和景丽 2020-12-08 02:41

Is there something similar to Pylint, that will look at a Python script (or run it), and determine which version of Python each line (or function) requires?

For exam

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-08 02:51

    The tool pyqver from Greg Hewgill wasn't updated since a while.

    vermin is a similar utility which shows in the verbose mode (-vvv) what lines are considered in the decision.

    % pip install vermin
    % vermin -vvv somescript.py
    Detecting python files..
    Analyzing using 8 processes..
    !2, 3.6      /path/to/somescript.py
      L13: f-strings require 3.6+
      L14: f-strings require 3.6+
      L15: f-strings require 3.6+
      L16: f-strings require 3.6+
      print(expr) requires 2+ or 3+
    
    Minimum required versions: 3.6
    Incompatible versions:     2
    

    Bonus: With the parameter -t=V you can define a target version V you want to be compatible with. If this version requirement is not met, the script will exit with an exit code 1, making it easy integratable into a test suite.

提交回复
热议问题