diff options
author | Anthony Sottile <asottile@umich.edu> | 2021-11-25 15:48:38 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-25 15:48:38 -0500 |
commit | b857d25c816d66bd15bb11dcb634b5f1bee98e23 (patch) | |
tree | 1c031242430c3885456d14d18783053f27a33366 | |
parent | 6e5600f8ec3f98fd052bd532470297e0a360750e (diff) | |
parent | 77a054688ba9f2e4e1f925dd89b1279504bddeac (diff) | |
download | flake8-b857d25c816d66bd15bb11dcb634b5f1bee98e23.tar.gz |
Merge pull request #1476 from asottile/files_not_nullable
refactor run_checks to not take an Optional list of filenames
-rw-r--r-- | src/flake8/api/legacy.py | 3 | ||||
-rw-r--r-- | src/flake8/checker.py | 9 | ||||
-rw-r--r-- | src/flake8/main/application.py | 11 | ||||
-rw-r--r-- | tests/integration/test_checker.py | 2 | ||||
-rw-r--r-- | tests/unit/test_checker_manager.py | 12 | ||||
-rw-r--r-- | tests/unit/test_legacy_api.py | 3 |
6 files changed, 18 insertions, 22 deletions
diff --git a/src/flake8/api/legacy.py b/src/flake8/api/legacy.py index ed54770..0d9875f 100644 --- a/src/flake8/api/legacy.py +++ b/src/flake8/api/legacy.py @@ -103,7 +103,8 @@ class StyleGuide: :rtype: flake8.api.legacy.Report """ - self._application.run_checks(paths) + self._application.options.filenames = paths + self._application.run_checks() self._application.report_errors() return Report(self._application) diff --git a/src/flake8/checker.py b/src/flake8/checker.py index 059d05c..d093f39 100644 --- a/src/flake8/checker.py +++ b/src/flake8/checker.py @@ -56,21 +56,18 @@ class Manager: together and make our output deterministic. """ - def __init__(self, style_guide, arguments, checker_plugins): + def __init__(self, style_guide, checker_plugins): """Initialize our Manager instance. :param style_guide: The instantiated style guide for this instance of Flake8. :type style_guide: flake8.style_guide.StyleGuide - :param list arguments: - The extra arguments parsed from the CLI (if any) :param checker_plugins: The plugins representing checks parsed from entry-points. :type checker_plugins: flake8.plugins.manager.Checkers """ - self.arguments = arguments self.style_guide = style_guide self.options = style_guide.options self.checks = checker_plugins @@ -112,7 +109,7 @@ class Manager: ) return 0 - if utils.is_using_stdin(self.arguments): + if utils.is_using_stdin(self.options.filenames): LOG.warning( "The --jobs option is not compatible with supplying " "input using - . Ignoring --jobs arguments." @@ -159,7 +156,7 @@ class Manager: def make_checkers(self, paths: Optional[List[str]] = None) -> None: """Create checkers for each file.""" if paths is None: - paths = self.arguments + paths = self.options.filenames checks = self.checks.to_dictionary() self._all_checkers = [ diff --git a/src/flake8/main/application.py b/src/flake8/main/application.py index 6825f91..4a060f9 100644 --- a/src/flake8/main/application.py +++ b/src/flake8/main/application.py @@ -246,28 +246,25 @@ class Application: def make_file_checker_manager(self) -> None: """Initialize our FileChecker Manager.""" - assert self.options is not None self.file_checker_manager = checker.Manager( style_guide=self.guide, - arguments=self.options.filenames, checker_plugins=self.check_plugins, ) - def run_checks(self, files: Optional[List[str]] = None) -> None: + def run_checks(self) -> None: """Run the actual checks with the FileChecker Manager. This method encapsulates the logic to make a :class:`~flake8.checker.Manger` instance run the checks it is managing. - - :param list files: - List of filenames to process """ assert self.file_checker_manager is not None if self.running_against_diff: - files = sorted(self.parsed_diff) + files: Optional[List[str]] = sorted(self.parsed_diff) if not files: return + else: + files = None self.file_checker_manager.start(files) try: diff --git a/tests/integration/test_checker.py b/tests/integration/test_checker.py index 7e0b975..29db6d3 100644 --- a/tests/integration/test_checker.py +++ b/tests/integration/test_checker.py @@ -293,7 +293,7 @@ def test_report_order(results, expected_order): # Create a placeholder manager without arguments or plugins # Just add one custom file checker which just provides the results - manager = checker.Manager(style_guide, [], []) + manager = checker.Manager(style_guide, []) manager.checkers = manager._all_checkers = [file_checker] # _handle_results is the first place which gets the sorted result diff --git a/tests/unit/test_checker_manager.py b/tests/unit/test_checker_manager.py index 6594453..09a0f65 100644 --- a/tests/unit/test_checker_manager.py +++ b/tests/unit/test_checker_manager.py @@ -22,7 +22,7 @@ def style_guide_mock(): def _parallel_checker_manager(): """Call Manager.run() and return the number of calls to `run_serial`.""" style_guide = style_guide_mock() - manager = checker.Manager(style_guide, [], []) + manager = checker.Manager(style_guide, []) # multiple checkers is needed for parallel mode manager.checkers = [mock.Mock(), mock.Mock()] return manager @@ -54,7 +54,7 @@ def test_oserrors_are_reraised(_): def test_multiprocessing_is_disabled(_): """Verify not being able to import multiprocessing forces jobs to 0.""" style_guide = style_guide_mock() - manager = checker.Manager(style_guide, [], []) + manager = checker.Manager(style_guide, []) assert manager.jobs == 0 @@ -68,7 +68,7 @@ def test_multiprocessing_cpu_count_not_implemented(): "cpu_count", side_effect=NotImplementedError, ): - manager = checker.Manager(style_guide, [], []) + manager = checker.Manager(style_guide, []) assert manager.jobs == 0 @@ -76,14 +76,14 @@ def test_multiprocessing_cpu_count_not_implemented(): def test_make_checkers(_): """Verify that we create a list of FileChecker instances.""" style_guide = style_guide_mock() - files = ["file1", "file2"] + style_guide.options.filenames = ["file1", "file2"] checkplugins = mock.Mock() checkplugins.to_dictionary.return_value = { "ast_plugins": [], "logical_line_plugins": [], "physical_line_plugins": [], } - manager = checker.Manager(style_guide, files, checkplugins) + manager = checker.Manager(style_guide, checkplugins) with mock.patch("flake8.utils.fnmatch", return_value=True): with mock.patch("flake8.processor.FileProcessor"): @@ -91,5 +91,5 @@ def test_make_checkers(_): assert manager._all_checkers for file_checker in manager._all_checkers: - assert file_checker.filename in files + assert file_checker.filename in style_guide.options.filenames assert not manager.checkers # the files don't exist diff --git a/tests/unit/test_legacy_api.py b/tests/unit/test_legacy_api.py index 671b21a..1033f5e 100644 --- a/tests/unit/test_legacy_api.py +++ b/tests/unit/test_legacy_api.py @@ -68,7 +68,8 @@ def test_styleguide_check_files(): style_guide = api.StyleGuide(app) report = style_guide.check_files(paths) - app.run_checks.assert_called_once_with(paths) + assert app.options.filenames == paths + app.run_checks.assert_called_once_with() app.report_errors.assert_called_once_with() assert isinstance(report, api.Report) |