Add type check for SubPattern's pattern arg

This commit is contained in:
Jan Petykiewicz 2020-03-14 15:53:35 -07:00
parent a4f556c3b3
commit e9244055c6

View File

@ -23,7 +23,7 @@ class SubPattern:
""" """
__slots__ = ('pattern', '_offset', '_rotation', '_dose', '_scale', '_mirrored', __slots__ = ('pattern', '_offset', '_rotation', '_dose', '_scale', '_mirrored',
'identifier', 'locked') 'identifier', 'locked')
pattern: 'Pattern' pattern: 'Pattern' or None
""" The `Pattern` being instanced """ """ The `Pattern` being instanced """
_offset: numpy.ndarray _offset: numpy.ndarray
@ -50,13 +50,17 @@ class SubPattern:
#TODO more documentation? #TODO more documentation?
def __init__(self, def __init__(self,
pattern: 'Pattern', pattern: 'Pattern' or None,
offset: vector2 = (0.0, 0.0), offset: vector2 = (0.0, 0.0),
rotation: float = 0.0, rotation: float = 0.0,
mirrored: List[bool] = None, mirrored: List[bool] = None,
dose: float = 1.0, dose: float = 1.0,
scale: float = 1.0, scale: float = 1.0,
locked: bool = False): locked: bool = False):
if pattern is not None and not hasattr(pattern, 'lock'):
raise PatternError('Provided pattern has no "lock()" method.\n'
'Maybe it''s not a Pattern instance?')
self.unlock() self.unlock()
self.identifier = () self.identifier = ()
self.pattern = pattern self.pattern = pattern