Add repetitions and split up code into traits
This commit is contained in:
parent
d4fbdd8d27
commit
bab40474a0
27 changed files with 1183 additions and 929 deletions
79
masque/traits/repeatable.py
Normal file
79
masque/traits/repeatable.py
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
from typing import List, Tuple, Callable, TypeVar, Optional
|
||||
from abc import ABCMeta, abstractmethod
|
||||
import copy
|
||||
import numpy
|
||||
|
||||
from ..error import PatternError, PatternLockedError
|
||||
|
||||
|
||||
T = TypeVar('T', bound='Repeatable')
|
||||
I = TypeVar('I', bound='RepeatableImpl')
|
||||
|
||||
|
||||
class Repeatable(metaclass=ABCMeta):
|
||||
"""
|
||||
Abstract class for all repeatable entities
|
||||
"""
|
||||
__slots__ = ()
|
||||
|
||||
'''
|
||||
---- Properties
|
||||
'''
|
||||
@property
|
||||
@abstractmethod
|
||||
def repetition(self) -> Optional['Repetition']:
|
||||
"""
|
||||
Repetition object, or None (single instance only)
|
||||
"""
|
||||
pass
|
||||
|
||||
@repetition.setter
|
||||
@abstractmethod
|
||||
def repetition(self, repetition: Optional['Repetition']):
|
||||
pass
|
||||
|
||||
'''
|
||||
---- Methods
|
||||
'''
|
||||
def set_repetition(self: T, repetition: Optional['Repetition']) -> T:
|
||||
"""
|
||||
Set the repetition
|
||||
|
||||
Args:
|
||||
repetition: new value for repetition, or None (single instance)
|
||||
|
||||
Returns:
|
||||
self
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class RepeatableImpl(Repeatable, metaclass=ABCMeta):
|
||||
"""
|
||||
Simple implementation of `Repeatable`
|
||||
"""
|
||||
__slots__ = ()
|
||||
|
||||
_repetition: Optional['Repetition']
|
||||
""" Repetition object, or None (single instance only) """
|
||||
|
||||
'''
|
||||
---- Non-abstract properties
|
||||
'''
|
||||
@property
|
||||
def repetition(self) -> Optional['Repetition']:
|
||||
return self._repetition
|
||||
|
||||
@repetition.setter
|
||||
def repetition(self, repetition: Optional['Repetition']):
|
||||
from ..repetition import Repetition
|
||||
if repetition is not None and not isinstance(repetition, Repetition):
|
||||
raise PatternError(f'{repetition} is not a valid Repetition object!')
|
||||
self._repetition = repetition
|
||||
|
||||
'''
|
||||
---- Non-abstract methods
|
||||
'''
|
||||
def set_repetition(self: I, repetition: 'Repetition') -> I:
|
||||
self.repetition = repetition
|
||||
return self
|
||||
Loading…
Add table
Add a link
Reference in a new issue