diff --git a/docs/source/internal/utils.rst b/docs/source/internal/utils.rst index 31e0d39..2b2638e 100644 --- a/docs/source/internal/utils.rst +++ b/docs/source/internal/utils.rst @@ -25,13 +25,8 @@ "E121,W123,F904" "E121,\nW123,\nF804" - "E121,\n\tW123,\n\tF804" - -Or it will take a list of strings (potentially with whitespace) such as - -.. code-block:: python - - [" E121\n", "\t\nW123 ", "\n\tF904\n "] + " E121,\n\tW123,\n\tF804 " + " E121\n\tW123 \n\tF804" And converts it to a list that looks as follows diff --git a/src/flake8/utils.py b/src/flake8/utils.py index cf88648..06a1db1 100644 --- a/src/flake8/utils.py +++ b/src/flake8/utils.py @@ -24,11 +24,11 @@ string_types = (str, type(u"")) def parse_comma_separated_list(value, regexp=COMMA_SEPARATED_LIST_RE): - # type: (Union[Sequence[str], str], Pattern[str]) -> List[str] + # type: (Optional[str], Pattern[str]) -> List[str] """Parse a comma-separated list. :param value: - String or list of strings to be parsed and normalized. + String to be parsed and normalized. :param regexp: Compiled regular expression used to split the value when it is a string. @@ -46,10 +46,8 @@ def parse_comma_separated_list(value, regexp=COMMA_SEPARATED_LIST_RE): if not value: return [] - if isinstance(value, string_types): - value = regexp.split(value) - - item_gen = (item.strip() for item in value) + separated = regexp.split(value) + item_gen = (item.strip() for item in separated) return [item for item in item_gen if item] diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 20c5fb9..b4bd1a1 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -22,11 +22,6 @@ RELATIVE_PATHS = ["flake8", "pep8", "pyflakes", "mccabe"] ("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"]), - (["E123", "\n\tW234", "", "\n E206", ""], ["E123", "W234", "E206"]), ]) def test_parse_comma_separated_list(value, expected): """Verify that similar inputs produce identical outputs."""