Skip to content

Commit

Permalink
Don't unnecessarily copy list in listify()
Browse files Browse the repository at this point in the history
  • Loading branch information
nsoranzo committed Dec 2, 2024
1 parent 2b5ecfb commit 0695bab
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/galaxy/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,9 @@ def listify(item: Any, do_strip: bool = False) -> List:
"""
if not item:
return []
elif isinstance(item, (list, tuple)):
elif isinstance(item, list):
return item
elif isinstance(item, tuple):
return list(item)
elif isinstance(item, str) and item.count(","):
if do_strip:
Expand Down
3 changes: 2 additions & 1 deletion test/unit/util/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ def test_listify() -> None:
assert util.listify("foo") == ["foo"]
assert util.listify("foo, bar") == ["foo", " bar"]
assert util.listify("foo, bar", do_strip=True) == ["foo", "bar"]
assert util.listify([1, 2, 3]) == [1, 2, 3]
list_ = [1, 2, 3]
assert util.listify(list_) is list_
assert util.listify((1, 2, 3)) == [1, 2, 3]
s = {1, 2, 3}
assert util.listify(s) == [s]
Expand Down

0 comments on commit 0695bab

Please sign in to comment.