Пример #1
0
 def __init__(
     self,
     items=None,
     item_class=None,
     ):
     from abjad.tools import datastructuretools
     prototype = (
         collections.Iterator,
         types.GeneratorType,
         )
     if isinstance(items, str):
         items = items.split()
     elif isinstance(items, prototype):
         items = [item for item in items]
     if item_class is None:
         item_class = self._named_item_class
         if items is not None:
             if isinstance(items, datastructuretools.TypedCollection) and \
                 issubclass(items.item_class, self._parent_item_class):
                 item_class = items.item_class
             elif len(items):
                 if isinstance(items, collections.Set):
                     items = tuple(items)
                 if isinstance(items[0], str):
                     item_class = self._named_item_class
                 elif isinstance(items[0], (int, float)):
                     item_class = self._numbered_item_class
                 elif isinstance(items[0], self._parent_item_class):
                     item_class = type(items[0])
     assert issubclass(item_class, self._parent_item_class)
     TypedTuple.__init__(
         self,
         items=items,
         item_class=item_class,
         )
Пример #2
0
 def __init__(
     self,
     items=None,
     item_class=None,
 ):
     from abjad.tools import datastructuretools
     prototype = (
         collections.Iterator,
         types.GeneratorType,
     )
     if isinstance(items, str):
         items = items.split()
     elif isinstance(items, prototype):
         items = [item for item in items]
     if item_class is None:
         item_class = self._named_item_class
         if items is not None:
             if isinstance(items, datastructuretools.TypedCollection) and \
                 issubclass(items.item_class, self._parent_item_class):
                 item_class = items.item_class
             elif len(items):
                 if isinstance(items, collections.Set):
                     items = tuple(items)
                 if isinstance(items[0], str):
                     item_class = self._named_item_class
                 elif isinstance(items[0], (int, float)):
                     item_class = self._numbered_item_class
                 elif isinstance(items[0], self._parent_item_class):
                     item_class = type(items[0])
     assert issubclass(item_class, self._parent_item_class)
     TypedTuple.__init__(
         self,
         items=items,
         item_class=item_class,
     )
Пример #3
0
 def __init__(
     self, 
     tokens=None, 
     item_class=None, 
     custom_identifier=None,
     ):
     from abjad.tools import datastructuretools
     from abjad.tools import pitchtools 
     if isinstance(tokens, str):
         tokens = tokens.split()
     elif isinstance(tokens, (
         collections.Iterator,
         types.GeneratorType,
         )):
         tokens = [token for token in tokens]
     if item_class is None:
         item_class = self._named_item_class
         if tokens is not None:
             if isinstance(tokens, datastructuretools.TypedCollection) and \
                 issubclass(tokens.item_class, self._parent_item_class):
                 item_class = tokens.item_class
             elif len(tokens):
                 if isinstance(tokens, collections.Set):
                     tokens = tuple(tokens)
                 if isinstance(tokens[0], str):
                     item_class = self._named_item_class
                 elif isinstance(tokens[0], (int, float)):
                     item_class = self._numbered_item_class
                 elif isinstance(tokens[0], self._parent_item_class):
                     item_class = type(tokens[0])
     assert issubclass(item_class, self._parent_item_class)
     TypedTuple.__init__(
         self,
         tokens=tokens,
         item_class=item_class,
         custom_identifier=custom_identifier,
         )