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."""