为什么我仍然在 Django v1.7.4 中使用 optparse?

Why do I still have optparse being used in Django v1.7.4?

argparse 是 Django(据称)用于解析命令行的工具,根据 this commit and this support ticket.

然而,九个月过去了,当我访问 BaseCommand 声明时,我看到:

from optparse import make_option, OptionParser

...

option_list = (
    make_option('-v', '--verbosity', action='store', dest='verbosity', default='1',
        type='choice', choices=['0', '1', '2', '3'],
        help='Verbosity level; 0=minimal output, 1=normal output, 2=verbose output, 3=very verbose output'),
    make_option('--settings',
        help='The Python path to a settings module, e.g. "myproject.settings.main". If this isn\'t provided, the DJANGO_SETTINGS_MODULE environment variable will be used.'),
    make_option('--pythonpath',
        help='A directory to add to the Python path, e.g. "/home/djangoprojects/myproject".'),
    make_option('--traceback', action='store_true',
        help='Raise on exception'),
    make_option('--no-color', action='store_true', dest='no_color', default=False,
        help="Don't colorize the command output."),
)

Django 什么时候在 1.7 中使用 argparse

您 link 的提交被标记为 v1.8b2。查看稳定版 v1.7.x and v1.8.x branches it looks like argparse will be introduced as the default in v1.8. See also the release notes for v1.8.

的源代码

但是,在 Django v2 之前,optparse 仍将作为后备选项(以允许继续支持 2.7/3.2 之前的 Python 版本)。根据 test source code:

optparse should be supported during Django 1.8/1.9 releases