[docs]classStringList(NamedList):""" List of strings. This mimics a regular Python list except that anything added to it will be coerced into a string. None values are also acceptable and are treated as missing strings. The list may also be named (see :py:class:`~NamedList`), which provides some dictionary-like functionality. """def__init__(self,data:Optional[Iterable]=None,names:Optional[Names]=None,_validate:bool=True,):""" Args: data: Some iterable object where all values can be coerced to strings or are None. Alternatively this may itself be None, which defaults to an empty list. names: Names for the list elements, defaults to an empty list. _validate: Internal use only. """if_validate:ifdataisnotNone:ifisinstance(data,StringList):data=data._dataelse:ifisinstance(data,NamedList):data=data._dataoriginal=datadata=list(_coerce_to_str(item)foriteminoriginal)super().__init__(data,names,_validate=_validate)
[docs]defset_value(self,index:Union[int,str],value:Any,in_place:bool=False)->"StringList":"""Calls :py:meth:`~biocutils.NamedList.NamedList.set_value` after coercing ``value`` to a string."""returnsuper().set_value(index,_coerce_to_str(value),in_place=in_place)
[docs]defset_slice(self,index:SubscriptTypes,value:Sequence,in_place:bool=False)->"StringList":"""Calls :py:meth:`~biocutils.NamedList.NamedList.set_slice` after coercing ``value`` to strings."""returnsuper().set_slice(index,_SubscriptCoercer(value),in_place=in_place)
[docs]defsafe_insert(self,index:Union[int,str],value:Any,in_place:bool=False)->"StringList":"""Calls :py:meth:`~biocutils.NamedList.NamedList.safe_insert` after coercing ``value`` to a string."""returnsuper().safe_insert(index,_coerce_to_str(value),in_place=in_place)
[docs]defsafe_append(self,value:Any,in_place:bool=False)->"StringList":"""Calls :py:meth:`~biocutils.NamedList.NamedList.safe_append` after coercing ``value`` to a string."""returnsuper().safe_append(_coerce_to_str(value),in_place=in_place)
[docs]defsafe_extend(self,other:Iterable,in_place:bool=True)->"StringList":"""Calls :py:meth:`~biocutils.NamedList.NamedList.safe_extend` after coercing elements of ``other`` to strings."""returnsuper().safe_extend((_coerce_to_str(y)foryinother),in_place=in_place)