diff --git a/src/flake8/main/application.py b/src/flake8/main/application.py index 421293c..6e5373f 100644 --- a/src/flake8/main/application.py +++ b/src/flake8/main/application.py @@ -97,8 +97,8 @@ class Application(object): #: The parsed diff information self.parsed_diff = {} # type: Dict[str, Set[int]] - def parse_preliminary_options_and_args(self, argv): - # type: (List[str]) -> None + def parse_preliminary_options_and_args(self, argv=None): + # type: (Optional[List[str]]) -> None """Get preliminary options and args from CLI, pre-plugin-loading. We need to know the values of a few standard options and args now, so @@ -121,7 +121,7 @@ class Application(object): # do not need to worry and we can continue. If it is, we successfully # defer printing the version until just a little bit later. # Similarly we have to defer printing the help text until later. - args = argv[:] + args = (argv if argv is not None else sys.argv)[:] try: args.remove("--version") except ValueError: @@ -344,7 +344,7 @@ class Application(object): self.formatter.show_statistics(self.guide.stats) def initialize(self, argv): - # type: (List[str]) -> None + # type: (Optional[List[str]]) -> None """Initialize the application to be run. This finds the plugins, registers their options, and parses the @@ -373,13 +373,13 @@ class Application(object): self.formatter.stop() def _run(self, argv): - # type: (List[str]) -> None + # type: (Optional[List[str]]) -> None self.initialize(argv) self.run_checks() self.report() - def run(self, argv): - # type: (List[str]) -> None + def run(self, argv=None): + # type: (Optional[List[str]]) -> None """Run our application. This method will also handle KeyboardInterrupt exceptions for the diff --git a/src/flake8/main/cli.py b/src/flake8/main/cli.py index c3db0eb..53f31e9 100644 --- a/src/flake8/main/cli.py +++ b/src/flake8/main/cli.py @@ -1,5 +1,4 @@ """Command-line implementation of flake8.""" -import sys from typing import List, Optional from flake8.main import application @@ -15,9 +14,6 @@ def main(argv=None): :param list argv: The arguments to be passed to the application for parsing. """ - if argv is None: - argv = sys.argv - app = application.Application() app.run(argv) app.exit() diff --git a/tests/integration/test_main.py b/tests/integration/test_main.py index 80ee50e..001f1ff 100644 --- a/tests/integration/test_main.py +++ b/tests/integration/test_main.py @@ -126,13 +126,3 @@ def test_bug_report_successful(capsys): out, err = capsys.readouterr() assert json.loads(out) assert err == '' - - -def test_obtaining_args_from_sys_argv_when_not_explicity_provided(capsys): - """Test that arguments are obtained from 'sys.argv'.""" - with mock.patch('sys.argv', ['--help']): - _call_main(None) - - out, err = capsys.readouterr() - assert out.startswith('usage: flake8 [options] file file ...\n') - assert err == ''