[docs]classBooleanList(NamedList):""" List of booleans. This mimics a regular Python list except that anything added to it will be coerced into a boolean. None values are also acceptable and are treated as missing booleans. 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 booleans 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,BooleanList):data=data._dataelse:ifisinstance(data,NamedList):data=data._dataoriginal=datadata=list(_coerce_to_bool(item)foriteminoriginal)super().__init__(data,names,_validate=_validate)
[docs]defset_value(self,index:Union[int,str],value:Any,in_place:bool=False)->"BooleanList":"""Calls :py:meth:`~biocutils.NamedList.NamedList.set_value` after coercing ``value`` to a boolean."""returnsuper().set_value(index,_coerce_to_bool(value),in_place=in_place)
[docs]defset_slice(self,index:SubscriptTypes,value:Sequence,in_place:bool=False)->"BooleanList":"""Calls :py:meth:`~biocutils.NamedList.NamedList.set_slice` after coercing ``value`` to booleans."""returnsuper().set_slice(index,_SubscriptCoercer(value),in_place=in_place)
[docs]defsafe_insert(self,index:Union[int,str],value:Any,in_place:bool=False)->"BooleanList":"""Calls :py:meth:`~biocutils.NamedList.NamedList.safe_insert` after coercing ``value`` to a boolean."""returnsuper().safe_insert(index,_coerce_to_bool(value),in_place=in_place)
[docs]defsafe_append(self,value:Any,in_place:bool=False)->"BooleanList":"""Calls :py:meth:`~biocutils.NamedList.NamedList.safe_append` after coercing ``value`` to a boolean."""returnsuper().safe_append(_coerce_to_bool(value),in_place=in_place)
[docs]defsafe_extend(self,other:Iterable,in_place:bool=True)->"BooleanList":"""Calls :py:meth:`~biocutils.NamedList.NamedList.safe_extend` after coercing elements of ``other`` to booleans."""returnsuper().safe_extend((_coerce_to_bool(y)foryinother),in_place=in_place)