From 7f46990f4b1dcd59e8c593538b37578cbf9f3d77 Mon Sep 17 00:00:00 2001 From: "Eric N. Vander Weele" Date: Fri, 25 Oct 2019 15:01:30 -0400 Subject: [PATCH] application: Change to `argparse.ArgumentParser` for preliminary parsing Now that preliminary options are registered with the preliminary parser on the `Application`, leverage that for parsing known options. This important change removes the `Application.option_manager` from being responsible for pre-configuration parsing and the workarounds needed in the `Application.parse_preliminary_options_and_args()` to account for the fact that `Application.option_manager` was aware of *all* options, not just the options necessary for pre-configuration loading. A following commit will address removing these workarounds. --- src/flake8/main/application.py | 2 +- tests/unit/test_application.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/flake8/main/application.py b/src/flake8/main/application.py index e183351..0f86844 100644 --- a/src/flake8/main/application.py +++ b/src/flake8/main/application.py @@ -138,7 +138,7 @@ class Application(object): except ValueError: pass - opts, args = self.option_manager.parse_known_args(args) + opts, args = self.prelim_arg_parser.parse_known_args(args) # parse_known_args includes unknown options as args args = [a for a in args if not a.startswith("-")] return opts, args diff --git a/tests/unit/test_application.py b/tests/unit/test_application.py index 09edfe4..15bc54d 100644 --- a/tests/unit/test_application.py +++ b/tests/unit/test_application.py @@ -93,9 +93,10 @@ def test_returns_specified_plugin(application): def test_prelim_opts_args(application): """Verify we get sensible prelim opts and args.""" opts, args = application.parse_preliminary_options_and_args( - ['flake8', '--foo', '--verbose', 'src', 'setup.py', '--statistics']) + ['--foo', '--verbose', 'src', 'setup.py', '--statistics']) - assert opts.statistics + assert not hasattr(opts, 'foo') + assert not hasattr(opts, 'statistics') assert opts.verbose assert args == ['src', 'setup.py']