options.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:flake8-polyfill 作者: PyCQA 项目源码 文件源码
def register(parser, *args, **kwargs):
    r"""Register an option for the Option Parser provided by Flake8.

    :param parser:
        The option parser being used by Flake8 to handle command-line options.
    :param \*args:
        Positional arguments that you might otherwise pass to ``add_option``.
    :param \*\*kwargs:
        Keyword arguments you might otherwise pass to ``add_option``.
    """
    try:
        # Flake8 3.x registration
        parser.add_option(*args, **kwargs)
    except (optparse.OptionError, TypeError):
        # Flake8 2.x registration
        # Pop Flake8 3 parameters out of the kwargs so they don't cause a
        # conflict.
        parse_from_config = kwargs.pop('parse_from_config', False)
        comma_separated_list = kwargs.pop('comma_separated_list', False)
        normalize_paths = kwargs.pop('normalize_paths', False)
        # In the unlikely event that the developer has specified their own
        # callback, let's pop that and deal with that as well.
        preexisting_callback = kwargs.pop('callback', None)
        callback = generate_callback_from(comma_separated_list,
                                          normalize_paths,
                                          preexisting_callback)

        if callback:
            kwargs['callback'] = callback
            kwargs['action'] = 'callback'

        # We've updated our args and kwargs and can now rather confidently
        # call add_option.
        option = parser.add_option(*args, **kwargs)
        if parse_from_config:
            parser.config_options.append(option.get_opt_string().lstrip('-'))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号