Add parent class MasqueError and use it for traits and all other exceptions
This commit is contained in:
parent
3653a33534
commit
4308bdeb56
@ -1,13 +1,15 @@
|
|||||||
class PatternError(Exception):
|
class MasqueError(Exception):
|
||||||
"""
|
"""
|
||||||
Simple Exception for Pattern objects and their contents
|
Parent exception for all Masque-related Exceptions
|
||||||
"""
|
"""
|
||||||
def __init__(self, value):
|
pass
|
||||||
self.value = value
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return repr(self.value)
|
|
||||||
|
|
||||||
|
class PatternError(MasqueError):
|
||||||
|
"""
|
||||||
|
Exception for Pattern objects and their contents
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
class PatternLockedError(PatternError):
|
class PatternLockedError(PatternError):
|
||||||
"""
|
"""
|
||||||
@ -17,7 +19,7 @@ class PatternLockedError(PatternError):
|
|||||||
PatternError.__init__(self, 'Tried to modify a locked Pattern, subpattern, or shape')
|
PatternError.__init__(self, 'Tried to modify a locked Pattern, subpattern, or shape')
|
||||||
|
|
||||||
|
|
||||||
class LibraryError(Exception):
|
class LibraryError(MasqueError):
|
||||||
"""
|
"""
|
||||||
Exception raised by Library classes
|
Exception raised by Library classes
|
||||||
"""
|
"""
|
||||||
|
@ -3,7 +3,7 @@ from typing import TypeVar
|
|||||||
from abc import ABCMeta, abstractmethod
|
from abc import ABCMeta, abstractmethod
|
||||||
|
|
||||||
from ..utils import annotations_t
|
from ..utils import annotations_t
|
||||||
from ..error import PatternError
|
from ..error import MasqueError
|
||||||
|
|
||||||
|
|
||||||
T = TypeVar('T', bound='Annotatable')
|
T = TypeVar('T', bound='Annotatable')
|
||||||
@ -51,5 +51,5 @@ class AnnotatableImpl(Annotatable, metaclass=ABCMeta):
|
|||||||
@annotations.setter
|
@annotations.setter
|
||||||
def annotations(self, annotations: annotations_t):
|
def annotations(self, annotations: annotations_t):
|
||||||
if not isinstance(annotations, dict):
|
if not isinstance(annotations, dict):
|
||||||
raise PatternError(f'annotations expected dict, got {type(annotations)}')
|
raise MasqueError(f'annotations expected dict, got {type(annotations)}')
|
||||||
self._annotations = annotations
|
self._annotations = annotations
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from typing import TypeVar
|
from typing import TypeVar
|
||||||
from abc import ABCMeta, abstractmethod
|
from abc import ABCMeta, abstractmethod
|
||||||
|
|
||||||
from ..error import PatternError
|
from ..error import MasqueError
|
||||||
|
|
||||||
|
|
||||||
T = TypeVar('T', bound='Doseable')
|
T = TypeVar('T', bound='Doseable')
|
||||||
@ -65,7 +65,7 @@ class DoseableImpl(Doseable, metaclass=ABCMeta):
|
|||||||
@dose.setter
|
@dose.setter
|
||||||
def dose(self, val: float):
|
def dose(self, val: float):
|
||||||
if not val >= 0:
|
if not val >= 0:
|
||||||
raise PatternError('Dose must be non-negative')
|
raise MasqueError('Dose must be non-negative')
|
||||||
self._dose = val
|
self._dose = val
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
@ -50,7 +50,7 @@ class Mirrorable(metaclass=ABCMeta):
|
|||||||
# @mirrored.setter
|
# @mirrored.setter
|
||||||
# def mirrored(self, val: Sequence[bool]):
|
# def mirrored(self, val: Sequence[bool]):
|
||||||
# if is_scalar(val):
|
# if is_scalar(val):
|
||||||
# raise PatternError('Mirrored must be a 2-element list of booleans')
|
# raise MasqueError('Mirrored must be a 2-element list of booleans')
|
||||||
# self._mirrored = numpy.array(val, dtype=bool, copy=True)
|
# self._mirrored = numpy.array(val, dtype=bool, copy=True)
|
||||||
#
|
#
|
||||||
# '''
|
# '''
|
||||||
|
@ -4,7 +4,7 @@ from typing import TypeVar
|
|||||||
from abc import ABCMeta, abstractmethod
|
from abc import ABCMeta, abstractmethod
|
||||||
import numpy # type: ignore
|
import numpy # type: ignore
|
||||||
|
|
||||||
from ..error import PatternError
|
from ..error import MasqueError
|
||||||
from ..utils import vector2
|
from ..utils import vector2
|
||||||
|
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ class PositionableImpl(Positionable, metaclass=ABCMeta):
|
|||||||
val = numpy.array(val, dtype=float)
|
val = numpy.array(val, dtype=float)
|
||||||
|
|
||||||
if val.size != 2:
|
if val.size != 2:
|
||||||
raise PatternError('Offset must be convertible to size-2 ndarray')
|
raise MasqueError('Offset must be convertible to size-2 ndarray')
|
||||||
self._offset = val.flatten()
|
self._offset = val.flatten()
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from typing import TypeVar, Optional, TYPE_CHECKING
|
from typing import TypeVar, Optional, TYPE_CHECKING
|
||||||
from abc import ABCMeta, abstractmethod
|
from abc import ABCMeta, abstractmethod
|
||||||
|
|
||||||
from ..error import PatternError
|
from ..error import MasqueError
|
||||||
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@ -71,7 +71,7 @@ class RepeatableImpl(Repeatable, metaclass=ABCMeta):
|
|||||||
def repetition(self, repetition: Optional['Repetition']):
|
def repetition(self, repetition: Optional['Repetition']):
|
||||||
from ..repetition import Repetition
|
from ..repetition import Repetition
|
||||||
if repetition is not None and not isinstance(repetition, Repetition):
|
if repetition is not None and not isinstance(repetition, Repetition):
|
||||||
raise PatternError(f'{repetition} is not a valid Repetition object!')
|
raise MasqueError(f'{repetition} is not a valid Repetition object!')
|
||||||
self._repetition = repetition
|
self._repetition = repetition
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
@ -5,7 +5,7 @@ import numpy # type: ignore
|
|||||||
from numpy import pi
|
from numpy import pi
|
||||||
|
|
||||||
#from .positionable import Positionable
|
#from .positionable import Positionable
|
||||||
from ..error import PatternError
|
from ..error import MasqueError
|
||||||
from ..utils import is_scalar, rotation_matrix_2d, vector2
|
from ..utils import is_scalar, rotation_matrix_2d, vector2
|
||||||
|
|
||||||
T = TypeVar('T', bound='Rotatable')
|
T = TypeVar('T', bound='Rotatable')
|
||||||
@ -57,7 +57,7 @@ class RotatableImpl(Rotatable, metaclass=ABCMeta):
|
|||||||
@rotation.setter
|
@rotation.setter
|
||||||
def rotation(self, val: float):
|
def rotation(self, val: float):
|
||||||
if not is_scalar(val):
|
if not is_scalar(val):
|
||||||
raise PatternError('Rotation must be a scalar')
|
raise MasqueError('Rotation must be a scalar')
|
||||||
self._rotation = val % (2 * pi)
|
self._rotation = val % (2 * pi)
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from typing import TypeVar
|
from typing import TypeVar
|
||||||
from abc import ABCMeta, abstractmethod
|
from abc import ABCMeta, abstractmethod
|
||||||
|
|
||||||
from ..error import PatternError
|
from ..error import MasqueError
|
||||||
from ..utils import is_scalar
|
from ..utils import is_scalar
|
||||||
|
|
||||||
|
|
||||||
@ -51,9 +51,9 @@ class ScalableImpl(Scalable, metaclass=ABCMeta):
|
|||||||
@scale.setter
|
@scale.setter
|
||||||
def scale(self, val: float):
|
def scale(self, val: float):
|
||||||
if not is_scalar(val):
|
if not is_scalar(val):
|
||||||
raise PatternError('Scale must be a scalar')
|
raise MasqueError('Scale must be a scalar')
|
||||||
if not val > 0:
|
if not val > 0:
|
||||||
raise PatternError('Scale must be positive')
|
raise MasqueError('Scale must be positive')
|
||||||
self._scale = val
|
self._scale = val
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
Loading…
Reference in New Issue
Block a user