From 38e9d5c2502c1c473c6257077ff3e2b9f21e7597 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Sun, 28 Jul 2024 20:06:09 -0700 Subject: [PATCH] use strict zip --- masque/builder/utils.py | 4 ++-- masque/ports.py | 10 +++++----- masque/shapes/arc.py | 4 ++-- masque/shapes/shape.py | 2 +- masque/utils/comparisons.py | 4 ++-- masque/utils/pack2d.py | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/masque/builder/utils.py b/masque/builder/utils.py index fe30cf4..c466c71 100644 --- a/masque/builder/utils.py +++ b/masque/builder/utils.py @@ -202,7 +202,7 @@ def ell( if extension < 0: ext_floor = -numpy.floor(extension) raise BuildError(f'Position is too close by at least {ext_floor}. Total extensions would be\n\t' - + '\n\t'.join(f'{key}: {off}' for key, off in zip(ports.keys(), offsets))) + + '\n\t'.join(f'{key}: {off}' for key, off in zip(ports.keys(), offsets, strict=True))) - result = dict(zip(ports.keys(), offsets)) + result = dict(zip(ports.keys(), offsets, strict=True)) return result diff --git a/masque/ports.py b/masque/ports.py index 86eadc4..8f6a817 100644 --- a/masque/ports.py +++ b/masque/ports.py @@ -294,14 +294,14 @@ class PortList(metaclass=ABCMeta): Raises: `PortError` if the ports are not properly aligned. """ - a_names, b_names = list(zip(*connections.items())) + a_names, b_names = list(zip(*connections.items(), strict=True)) a_ports = [self.ports[pp] for pp in a_names] b_ports = [self.ports[pp] for pp in b_names] a_types = [pp.ptype for pp in a_ports] b_types = [pp.ptype for pp in b_ports] - type_conflicts = numpy.array([at != bt and at != 'unk' and bt != 'unk' - for at, bt in zip(a_types, b_types)]) + type_conflicts = numpy.array([at != bt and 'unk' not in (at, bt) + for at, bt in zip(a_types, b_types, strict=True)]) if type_conflicts.any(): msg = 'Ports have conflicting types:\n' @@ -502,8 +502,8 @@ class PortList(metaclass=ABCMeta): o_offsets[:, 1] *= -1 o_rotations *= -1 - type_conflicts = numpy.array([st != ot and st != 'unk' and ot != 'unk' - for st, ot in zip(s_types, o_types)]) + type_conflicts = numpy.array([st != ot and 'unk' not in (st, ot) + for st, ot in zip(s_types, o_types, strict=True)]) if type_conflicts.any(): msg = 'Ports have conflicting types:\n' for nn, (k, v) in enumerate(map_in.items()): diff --git a/masque/shapes/arc.py b/masque/shapes/arc.py index aa171ed..da10d0d 100644 --- a/masque/shapes/arc.py +++ b/masque/shapes/arc.py @@ -324,7 +324,7 @@ class Arc(Shape): mins = [] maxs = [] - for a, sgn in zip(a_ranges, (-1, +1)): + for a, sgn in zip(a_ranges, (-1, +1), strict=True): wh = sgn * self.width / 2 rx = self.radius_x + wh ry = self.radius_y + wh @@ -435,7 +435,7 @@ class Arc(Shape): mins = [] maxs = [] - for a, sgn in zip(a_ranges, (-1, +1)): + for a, sgn in zip(a_ranges, (-1, +1), strict=True): wh = sgn * self.width / 2 rx = self.radius_x + wh ry = self.radius_y + wh diff --git a/masque/shapes/shape.py b/masque/shapes/shape.py index 9f5dd19..b7b74d6 100644 --- a/masque/shapes/shape.py +++ b/masque/shapes/shape.py @@ -135,7 +135,7 @@ class Shape(PositionableImpl, Rotatable, Mirrorable, Copyable, Scalable, vertex_lists = [] p_verts = polygon.vertices + polygon.offset - for v, v_next in zip(p_verts, numpy.roll(p_verts, -1, axis=0)): + for v, v_next in zip(p_verts, numpy.roll(p_verts, -1, axis=0), strict=True): dv = v_next - v # Find x-index bounds for the line # TODO: fix this and err_xmin/xmax for grids smaller than the line / shape diff --git a/masque/utils/comparisons.py b/masque/utils/comparisons.py index 5de8f4a..63981c9 100644 --- a/masque/utils/comparisons.py +++ b/masque/utils/comparisons.py @@ -29,7 +29,7 @@ def annotations_lt(aa: annotations_t, bb: annotations_t) -> bool: if len(va) != len(vb): return len(va) < len(vb) - for aaa, bbb in zip(va, vb): + for aaa, bbb in zip(va, vb, strict=True): if aaa != bbb: return annotation2key(aaa) < annotation2key(bbb) return False @@ -55,7 +55,7 @@ def annotations_eq(aa: annotations_t, bb: annotations_t) -> bool: if len(va) != len(vb): return False - for aaa, bbb in zip(va, vb): + for aaa, bbb in zip(va, vb, strict=True): if aaa != bbb: return False diff --git a/masque/utils/pack2d.py b/masque/utils/pack2d.py index 7405406..5de9728 100644 --- a/masque/utils/pack2d.py +++ b/masque/utils/pack2d.py @@ -236,7 +236,7 @@ def pack_patterns( locations, reject_inds = packer(sizes, containers, presort=presort, allow_rejects=allow_rejects) pat = Pattern() - for pp, oo, loc in zip(patterns, offsets, locations): + for pp, oo, loc in zip(patterns, offsets, locations, strict=True): pat.ref(pp, offset=oo + loc) rejects = [patterns[ii] for ii in reject_inds]