@@ -58,12 +58,13 @@ def optional_values_list_to_string(
5858
5959
6060@singledispatch
61- def optional_symbols_list_to_string (
61+ def optional_symbols_list_to_list (
6262 symbols : Iterable [str ] | Iterable [Number ] | str | Number | None ,
6363 stype_in : SType ,
64- ) -> str :
64+ ) -> list [ str ] :
6565 """
66- Concatenate a symbols string or iterable of symbol strings (if not None).
66+ Create a list from a symbols string or iterable of symbol strings (if not
67+ None).
6768
6869 Parameters
6970 ----------
@@ -74,11 +75,11 @@ def optional_symbols_list_to_string(
7475
7576 Returns
7677 -------
77- str
78+ list[ str]
7879
7980 Notes
8081 -----
81- If None is given, ALL_SYMBOLS is returned.
82+ If None is given, [ ALL_SYMBOLS] is returned.
8283
8384 """
8485 raise TypeError (
@@ -87,48 +88,48 @@ def optional_symbols_list_to_string(
8788 )
8889
8990
90- @optional_symbols_list_to_string .register
91- def _ (_ : None , __ : SType ) -> str :
91+ @optional_symbols_list_to_list .register
92+ def _ (_ : None , __ : SType ) -> list [ str ] :
9293 """
93- Dispatch method for optional_symbols_list_to_string . Handles None which
94- defaults to ALL_SYMBOLS.
94+ Dispatch method for optional_symbols_list_to_list . Handles None which
95+ defaults to [ ALL_SYMBOLS] .
9596
9697 See Also
9798 --------
98- optional_symbols_list_to_string
99+ optional_symbols_list_to_list
99100
100101 """
101- return ALL_SYMBOLS
102+ return [ ALL_SYMBOLS ]
102103
103104
104- @optional_symbols_list_to_string .register
105- def _ (symbols : Number , stype_in : SType ) -> str :
105+ @optional_symbols_list_to_list .register
106+ def _ (symbols : Number , stype_in : SType ) -> list [ str ] :
106107 """
107- Dispatch method for optional_symbols_list_to_string . Handles numerical
108- types, alerting when an integer is given for STypes that expect strings.
108+ Dispatch method for optional_symbols_list_to_list . Handles numerical types,
109+ alerting when an integer is given for STypes that expect strings.
109110
110111 See Also
111112 --------
112- optional_symbols_list_to_string
113+ optional_symbols_list_to_list
113114
114115 """
115116 if stype_in == SType .INSTRUMENT_ID :
116- return str (symbols )
117+ return [ str (symbols )]
117118 raise ValueError (
118119 f"value `{ symbols } ` is not a valid symbol for stype { stype_in } ; "
119120 "did you mean to use `instrument_id`?" ,
120121 )
121122
122123
123- @optional_symbols_list_to_string .register
124- def _ (symbols : str , stype_in : SType ) -> str :
124+ @optional_symbols_list_to_list .register
125+ def _ (symbols : str , stype_in : SType ) -> list [ str ] :
125126 """
126- Dispatch method for optional_symbols_list_to_string . Handles str, splitting
127+ Dispatch method for optional_symbols_list_to_list . Handles str, splitting
127128 on commas and validating smart symbology.
128129
129130 See Also
130131 --------
131- optional_symbols_list_to_string
132+ optional_symbols_list_to_list
132133
133134 """
134135 if not symbols :
@@ -137,35 +138,33 @@ def _(symbols: str, stype_in: SType) -> str:
137138 "an empty string is not allowed" ,
138139 )
139140
140- if "," in symbols :
141- symbol_to_string = partial (
142- optional_symbols_list_to_string ,
143- stype_in = stype_in ,
144- )
145- symbol_list = symbols .strip ().strip ("," ).split ("," )
146- return "," .join (map (symbol_to_string , symbol_list ))
141+ symbol_list = symbols .strip ().strip ("," ).split ("," )
147142
148143 if stype_in in (SType .PARENT , SType .CONTINUOUS ):
149- return validate_smart_symbol (symbols )
150- return symbols .strip ().upper ()
144+ return list (map (str .strip , map (validate_smart_symbol , symbol_list )))
145+
146+ return list (map (str .upper , map (str .strip , symbol_list )))
151147
152148
153- @optional_symbols_list_to_string .register (cls = Iterable )
154- def _ (symbols : Iterable [str ] | Iterable [int ], stype_in : SType ) -> str :
149+ @optional_symbols_list_to_list .register (cls = Iterable )
150+ def _ (symbols : Iterable [str ] | Iterable [int ], stype_in : SType ) -> list [ str ] :
155151 """
156- Dispatch method for optional_symbols_list_to_string . Handles Iterables by
152+ Dispatch method for optional_symbols_list_to_list . Handles Iterables by
157153 dispatching the individual members.
158154
159155 See Also
160156 --------
161- optional_symbols_list_to_string
157+ optional_symbols_list_to_list
162158
163159 """
164- symbol_to_string = partial (
165- optional_symbols_list_to_string ,
160+ symbol_to_list = partial (
161+ optional_symbols_list_to_list ,
166162 stype_in = stype_in ,
167163 )
168- return "," .join (map (symbol_to_string , symbols ))
164+ aggregated : list [str ] = []
165+ for sym in map (symbol_to_list , symbols ):
166+ aggregated .extend (sym )
167+ return aggregated
169168
170169
171170def optional_date_to_string (value : date | str | None ) -> str | None :
0 commit comments