Skip to content

Commit 5c089b7

Browse files
committed
refactor starfile iterable loop
1 parent f1b618d commit 5c089b7

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/aspire/storage/starfile.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ def __init__(self, filepath="", blocks=None):
2222
for k in blocks:
2323
for _k, _v in blocks[k].items():
2424
if not isinstance(_v, str):
25-
if hasattr(_v, "__iter__"):
26-
blocks[k][_k] = list(map(str, _v))
27-
else:
25+
try:
26+
# Cast iterable elements to string.
27+
blocks[k][_k] = list(map(str, iter(_v)))
28+
except TypeError:
29+
# Singleton, cast to string.
2830
blocks[k][_k] = str(_v)
2931

3032
self.blocks = blocks or OrderedDict()

0 commit comments

Comments
 (0)