Skip to content

Commit

Permalink
Merge pull request #678 from gmatteo/master
Browse files Browse the repository at this point in the history
Fix serious regression introduced in list_strings
  • Loading branch information
shyuep committed May 24, 2024
2 parents 7568d6a + 50f17c3 commit 8b63bf1
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions monty/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from __future__ import annotations

from typing import TYPE_CHECKING, cast
from typing import TYPE_CHECKING, Iterable, cast

if TYPE_CHECKING:
from typing import Any, Union
Expand Down Expand Up @@ -34,7 +34,7 @@ def is_string(s: Any) -> bool:
return False


def list_strings(arg: Union[str, list[str]]) -> list[str]:
def list_strings(arg: Union[str, Iterable[str]]) -> list[str]:
"""
Always return a list of strings, given a string or list of strings as
input.
Expand All @@ -48,15 +48,17 @@ def list_strings(arg: Union[str, list[str]]) -> list[str]:
>>> list_strings(['A','list','of','strings'])
['A', 'list', 'of', 'strings']
>>> list_strings(('A','list','of','strings'))
['A', 'list', 'of', 'strings']
>>> list_strings({"a": 1, "b": 2}.keys())
['a', 'b']
"""
if is_string(arg):
return [cast(str, arg)]

elif isinstance(arg, list):
return arg

else:
raise TypeError("Wrong type, expect str or list[str].")
return [cast(str, s) for s in arg]


def marquee(text: str = "", width: int = 78, mark: str = "*") -> str:
Expand Down

0 comments on commit 8b63bf1

Please sign in to comment.