From fabb13c5d1577fd965a78d30143accabf3213256 Mon Sep 17 00:00:00 2001 From: Fabian Neundorf Date: Sat, 9 Jul 2016 19:27:19 +0000 Subject: [PATCH] Use option name provided by the parser When calling `add_option` it returns an `Option` object which can return the primary name of the option via `get_opt_name`. This should be used primarily in the cross compatible implementation so that the order of parameters does not matter. --- docs/source/plugin-development/cross-compatibility.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/source/plugin-development/cross-compatibility.rst b/docs/source/plugin-development/cross-compatibility.rst index ed8762f..e1c7cf6 100644 --- a/docs/source/plugin-development/cross-compatibility.rst +++ b/docs/source/plugin-development/cross-compatibility.rst @@ -120,9 +120,9 @@ options with |Flake8| and have it work on |Flake8| 2.x and 3.x. except (optparse.OptionError, TypeError): # Flake8 2.x registration parse_from_config = option_kwargs.pop('parse_from_config', False) - parser.add_option(*option_args, **option_kwargs) + option = parser.add_option(*option_args, **option_kwargs) if parse_from_config: - parser.config_options.append(option_args[-1].lstrip('-')) + parser.config_options.append(option.get_opt_string().lstrip('-')) Or, you can write a tiny helper function: @@ -140,9 +140,9 @@ Or, you can write a tiny helper function: parse_from_config = kwargs.pop('parse_from_config', False) kwargs.pop('comma_separated_list', False) kwargs.pop('normalize_paths', False) - parser.add_option(*args, **kwargs) + option = parser.add_option(*args, **kwargs) if parse_from_config: - parser.config_options.append(args[-1].lstrip('-')) + parser.config_options.append(option.get_opt_string().lstrip('-')) .. code-block:: python