type-related fixes and improvements

This commit is contained in:
Jan Petykiewicz 2020-11-09 22:04:04 -08:00
parent 4308bdeb56
commit 09a5e4a2db
5 changed files with 17 additions and 16 deletions

View File

@ -70,7 +70,7 @@ def write(pattern: Pattern,
"""
#TODO consider supporting DXF arcs?
if disambiguate_func is None:
disambiguate_func = disambiguate_pattern_names
disambiguate_func = lambda pats: disambiguate_pattern_names(pats)
assert(disambiguate_func is not None)
if not modify_originals:
@ -349,7 +349,7 @@ def _mlayer2dxf(layer: layer_t) -> str:
raise PatternError(f'Unknown layer type: {layer} ({type(layer)})')
def disambiguate_pattern_names(patterns: Sequence[Pattern],
def disambiguate_pattern_names(patterns: Iterable[Pattern],
max_name_length: int = 32,
suffix_length: int = 6,
dup_warn_filter: Callable[[str], bool] = None, # If returns False, don't warn about this name

View File

@ -674,7 +674,7 @@ def annotations_to_properties(annotations: annotations_t) -> List[fatrec.Propert
for key, values in annotations.items():
vals = [AString(v) if isinstance(v, str) else v
for v in values]
properties.append(fatrec.Property(key, vals, is_standard=False))
properties.append(fatrec.Property(key, vals, is_standard=False)) # type: ignore
return properties

View File

@ -58,11 +58,11 @@ class Label(PositionableImpl, LayerableImpl, LockableImpl, RepeatableImpl, Annot
self.set_locked(locked)
def __copy__(self: L) -> L:
return Label(string=self.string,
offset=self.offset.copy(),
layer=self.layer,
repetition=self.repetition,
locked=self.locked)
return type(self)(string=self.string,
offset=self.offset.copy(),
layer=self.layer,
repetition=self.repetition,
locked=self.locked)
def __deepcopy__(self: L, memo: Dict = None) -> L:
memo = {} if memo is None else memo

View File

@ -2,7 +2,7 @@
Base object representing a lithography mask.
"""
from typing import List, Callable, Tuple, Dict, Union, Set, Sequence, Optional, Type, overload
from typing import List, Callable, Tuple, Dict, Union, Set, Sequence, Optional, Type, overload, cast
from typing import MutableMapping, Iterable, TypeVar, Any
import copy
import pickle
@ -18,7 +18,8 @@ from .shapes import Shape, Polygon
from .label import Label
from .utils import rotation_matrix_2d, vector2, normalize_mirror, AutoSlots, annotations_t
from .error import PatternError, PatternLockedError
from .traits import LockableImpl, AnnotatableImpl, Scalable
from .traits import LockableImpl, AnnotatableImpl, Scalable, Mirrorable
from .traits import Rotatable, Positionable
visitor_function_t = Callable[['Pattern', Tuple['Pattern'], Dict, numpy.ndarray], 'Pattern']
@ -27,7 +28,7 @@ visitor_function_t = Callable[['Pattern', Tuple['Pattern'], Dict, numpy.ndarray]
P = TypeVar('P', bound='Pattern')
class Pattern(LockableImpl, AnnotatableImpl, metaclass=AutoSlots):
class Pattern(LockableImpl, AnnotatableImpl, Mirrorable, metaclass=AutoSlots):
"""
2D layout consisting of some set of shapes, labels, and references to other Pattern objects
(via SubPattern). Shapes are assumed to inherit from masque.shapes.Shape or provide equivalent functions.
@ -710,7 +711,7 @@ class Pattern(LockableImpl, AnnotatableImpl, metaclass=AutoSlots):
self
"""
for entry in chain(self.shapes, self.subpatterns):
entry.rotate(rotation)
cast(Rotatable, entry).rotate(rotation)
return self
def mirror_element_centers(self: P, axis: int) -> P:
@ -741,7 +742,7 @@ class Pattern(LockableImpl, AnnotatableImpl, metaclass=AutoSlots):
self
"""
for entry in chain(self.shapes, self.subpatterns):
entry.mirror(axis)
cast(Mirrorable, entry).mirror(axis)
return self
def mirror(self: P, axis: int) -> P:
@ -856,7 +857,7 @@ class Pattern(LockableImpl, AnnotatableImpl, metaclass=AutoSlots):
"""
self.lock()
for ss in chain(self.shapes, self.labels):
ss.lock()
ss.lock() # type: ignore # mypy struggles with multiple inheritance :(
for sp in self.subpatterns:
sp.deeplock()
return self
@ -873,7 +874,7 @@ class Pattern(LockableImpl, AnnotatableImpl, metaclass=AutoSlots):
"""
self.unlock()
for ss in chain(self.shapes, self.labels):
ss.unlock()
ss.unlock() # type: ignore # mypy struggles with multiple inheritance :(
for sp in self.subpatterns:
sp.deepunlock()
return self

View File

@ -79,7 +79,7 @@ class SubPattern(PositionableImpl, DoseableImpl, RotatableImpl, ScalableImpl, Mi
self.dose = dose
self.scale = scale
if mirrored is None:
mirrored = [False, False]
mirrored = (False, False)
self.mirrored = mirrored
self.repetition = repetition
self.annotations = annotations if annotations is not None else {}