From 25566468a22b348a9d1e0abd9395703658728402 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Sat, 20 May 2017 20:26:27 -0500 Subject: [PATCH] Filter out empty ignore/select codes When we parse out our comma separated lists, we should ignore empty strings to avoid them breaking users' expectations. Closes #330 --- src/flake8/utils.py | 3 ++- tests/unit/test_utils.py | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/flake8/utils.py b/src/flake8/utils.py index 4eb6537..a4c67ce 100644 --- a/src/flake8/utils.py +++ b/src/flake8/utils.py @@ -29,7 +29,8 @@ def parse_comma_separated_list(value): if not isinstance(value, (list, tuple)): value = value.split(',') - return [item.strip() for item in value] + item_gen = (item.strip() for item in value) + return [item for item in item_gen if item] def normalize_paths(paths, parent=os.curdir): diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 79d83cf..0a12f2d 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -13,8 +13,13 @@ RELATIVE_PATHS = ["flake8", "pep8", "pyflakes", "mccabe"] @pytest.mark.parametrize("value,expected", [ ("E123,\n\tW234,\n E206", ["E123", "W234", "E206"]), ("E123,W234,E206", ["E123", "W234", "E206"]), + ("E123,W234,E206,", ["E123", "W234", "E206"]), + ("E123,W234,,E206,,", ["E123", "W234", "E206"]), + ("E123,,W234,,E206,,", ["E123", "W234", "E206"]), (["E123", "W234", "E206"], ["E123", "W234", "E206"]), (["E123", "\n\tW234", "\n E206"], ["E123", "W234", "E206"]), + (["E123", "\n\tW234", "\n E206", "\n"], ["E123", "W234", "E206"]), + (["E123", "\n\tW234", "", "\n E206", "\n"], ["E123", "W234", "E206"]), ]) def test_parse_comma_separated_list(value, expected): """Verify that similar inputs produce identical outputs."""