Skip to content

Commit 95e6c63

Browse files
committed
Simplify to_string
1 parent 7ae8500 commit 95e6c63

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

pygmt/alias.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def to_string(
1515
prefix: str = "", # Default to an empty string to simplify the code logic.
1616
separator: Literal["/", ","] | None = None,
1717
mapping: bool | Mapping = False,
18-
) -> str | Sequence[str] | None:
18+
) -> str | list[str] | None:
1919
"""
2020
Convert any value to a string, a sequence of strings or None.
2121
@@ -100,11 +100,9 @@ def to_string(
100100
# Convert a sequence of values to a sequence of strings.
101101
# In some cases, "prefix" and "mapping" are ignored. We can enable them when needed.
102102
_values = [str(item) for item in value]
103-
if separator is None:
104-
# Sequence is given but separator is not specified. Return a sequence of strings
105-
# for repeatable GMT options like '-B'.
106-
return _values
107-
return f"{prefix}{separator.join(_values)}"
103+
# When separator is not specified, return a sequence of strings for repeatable GMT
104+
# options like '-B'. Otherwise, join the sequence of strings with the separator.
105+
return _values if separator is None else f"{prefix}{separator.join(_values)}"
108106

109107

110108
@dataclasses.dataclass

0 commit comments

Comments
 (0)