最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Am I using a "backported module"? - Stack Overflow

programmeradmin3浏览0评论

I'm trying to use the Python vermin utility to determine the minimum version needed to run a script of mine. Running it, I get:

$ vermin --no-parse-comments foo.py
Tips:
- You're using potentially backported modules: argparse
  If so, try using the following for better results: --backport argparse
(disable using: --no-tips)

Minimum required versions: 2.7, 3.2

First, I'm not even sure what backporting means. That is, if the authors of argparse have versions of it which work with different versions of Python, does that count as back-porting? Isn't it just the supported version range? Or - does it have to be someone else who has taken some kind of "back-porting" action?

Second, suppose we've agreed on what that means. How can I tell whether I'm "using a back-ported module"? Is it the way I'm using it, or is it that I take it from some location that indicates "back-porting"?

Additional info (ask for anything else that might help):

$ python3 --version
Python 3.6.5
$ pip3 show argparse
Name: argparse
Version: 1.4.0
Summary: Python command-line parsing library
Home-page: /
Author: Thomas Waldmann
Author-email: [email protected]
License: Python Software Foundation License
Location: /home/joeuser/.local/lib/python3.6/site-packages
Requires:
Required-by: ptop

I'm trying to use the Python vermin utility to determine the minimum version needed to run a script of mine. Running it, I get:

$ vermin --no-parse-comments foo.py
Tips:
- You're using potentially backported modules: argparse
  If so, try using the following for better results: --backport argparse
(disable using: --no-tips)

Minimum required versions: 2.7, 3.2

First, I'm not even sure what backporting means. That is, if the authors of argparse have versions of it which work with different versions of Python, does that count as back-porting? Isn't it just the supported version range? Or - does it have to be someone else who has taken some kind of "back-porting" action?

Second, suppose we've agreed on what that means. How can I tell whether I'm "using a back-ported module"? Is it the way I'm using it, or is it that I take it from some location that indicates "back-porting"?

Additional info (ask for anything else that might help):

$ python3 --version
Python 3.6.5
$ pip3 show argparse
Name: argparse
Version: 1.4.0
Summary: Python command-line parsing library
Home-page: https://github/ThomasWaldmann/argparse/
Author: Thomas Waldmann
Author-email: [email protected]
License: Python Software Foundation License
Location: /home/joeuser/.local/lib/python3.6/site-packages
Requires:
Required-by: ptop
Share Improve this question asked Mar 19 at 16:37 einpoklumeinpoklum 133k80 gold badges421 silver badges864 bronze badges 2
  • 2 argparse has been a part of the Python standard library since versions 2.7 and 3.2 - but there's also a standalone version on PyPI (this is the "backport") that works as far back as 2.3 and 3.1. vermin can't tell which of these two implementations you intend to use; it is by default showing you minimum versions for the built-in version, but letting you know that you could specify -backport to get results for the standalone version. – jasonharper Commented Mar 19 at 17:08
  • @jasonharper: So, PyPi argparse and standard-library argparse are two different things? Hmm. Also, it seems that what you're describing is a dilemma not regarding my script, but regarding what constitutes "usable with Python X.Y", i.e. is something considered usable based on PyPi modules or only on the standard library. – einpoklum Commented Mar 19 at 17:19
Add a comment  | 

1 Answer 1

Reset to default 0

Backported means to take a feature from a newer version of something and make it available to an older version of something. Specifically, vermin is talking about backporting features from the python standard library. The most common example of backporting in python is the typing_extensions module. This module takes new features from the typing module and makes them available to older versions of python. For instance, python 3.11 added the Self type to typing. This type is not available in the typing module for python 3.10 or lower. If you have one of those older versions of python, then you can install typing_extensions>=4 to make Self available from the typing_extensions module.

The vermin message means that as you are using the argparse module, this limits your code to using python 2.7, or python 3.2 or newer. As these are the first versions of python to introduce the argparse module. If you want to be able to use earlier versions of python (ie. <=2.6 or >=3.0,<3.2), then you will need to use a backported version of argparse. That is, the one in PyPI. Vermin is saying, if you try using the backported version, then your code might work with even earlier versions of python. However, the flip side is that you might lose access to certain features as the last version of argparse published on PyPI was 10 years ago.

In this context, it should be pretty obvious if you are using a backported module or not. Did you do pip install argparse or likewise put it in your requirements.txt? If not, then you are not using a backported module.

发布评论

评论列表(0)

  1. 暂无评论