enable annotations=None by default

This commit is contained in:
Jan Petykiewicz 2026-04-02 15:56:42 -07:00
commit 7130d26112
4 changed files with 45 additions and 3 deletions

View file

@ -66,7 +66,7 @@ class Label(PositionableImpl, RepeatableImpl, AnnotatableImpl, Bounded, Pivotabl
new._string = string
new._offset = offset
new._repetition = repetition
new._annotations = annotations if annotations is not None else {}
new._annotations = annotations
return new
def __copy__(self) -> Self:

View file

@ -103,7 +103,7 @@ class Ref(
new._scale = scale
new._mirrored = mirrored
new._repetition = repetition
new._annotations = annotations if annotations is not None else {}
new._annotations = annotations
return new
def __copy__(self) -> 'Ref':

View file

@ -19,7 +19,7 @@ if not gdsii_arrow.is_available():
def _annotations_key(annotations: dict[str, list[object]] | None) -> tuple[tuple[str, tuple[object, ...]], ...] | None:
if annotations is None:
if not annotations:
return None
return tuple(sorted((key, tuple(values)) for key, values in annotations.items()))
@ -228,6 +228,25 @@ def test_raw_ref_grid_label_constructors_match_public() -> None:
public_grid = Grid(a_vector=(20, 0), a_count=3, b_vector=(0, 30), b_count=2)
assert raw_grid == public_grid
raw_ref_empty = Ref._from_raw(
offset=numpy.array([100, 200]),
rotation=numpy.pi / 2,
mirrored=False,
scale=1.0,
repetition=None,
annotations=None,
)
public_ref_empty = Ref(
offset=(100, 200),
rotation=numpy.pi / 2,
mirrored=False,
scale=1.0,
repetition=None,
annotations=None,
)
assert raw_ref_empty.annotations is None
assert raw_ref_empty == public_ref_empty
raw_ref = Ref._from_raw(
offset=numpy.array([100, 200]),
rotation=numpy.pi / 2,
@ -247,6 +266,19 @@ def test_raw_ref_grid_label_constructors_match_public() -> None:
assert raw_ref == public_ref
assert numpy.array_equal(raw_ref.as_transforms(), public_ref.as_transforms())
raw_label_empty = Label._from_raw(
'LEAF',
offset=numpy.array([3, 4]),
annotations=None,
)
public_label_empty = Label(
'LEAF',
offset=(3, 4),
annotations=None,
)
assert raw_label_empty.annotations is None
assert raw_label_empty == public_label_empty
raw_label = Label._from_raw(
'LEAF',
offset=numpy.array([3, 4]),

View file

@ -9,7 +9,15 @@ def annotation2key(aaa: int | float | str) -> tuple[bool, Any]:
return (isinstance(aaa, str), aaa)
def _normalized_annotations(annotations: annotations_t) -> annotations_t:
if not annotations:
return None
return annotations
def annotations_lt(aa: annotations_t, bb: annotations_t) -> bool:
aa = _normalized_annotations(aa)
bb = _normalized_annotations(bb)
if aa is None:
return bb is not None
elif bb is None: # noqa: RET505
@ -36,6 +44,8 @@ def annotations_lt(aa: annotations_t, bb: annotations_t) -> bool:
def annotations_eq(aa: annotations_t, bb: annotations_t) -> bool:
aa = _normalized_annotations(aa)
bb = _normalized_annotations(bb)
if aa is None:
return bb is None
elif bb is None: # noqa: RET505