From 240007eb7ae827ca76415046bcaa80a8027708da Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Thu, 30 Oct 2025 01:13:23 -0700 Subject: [PATCH] misc cleanup: variable naming, typing, comments --- masque/error.py | 4 +++- masque/ports.py | 22 +++++++++++----------- masque/traits/positionable.py | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/masque/error.py b/masque/error.py index 0e46849..00775d3 100644 --- a/masque/error.py +++ b/masque/error.py @@ -25,12 +25,14 @@ class BuildError(MasqueError): """ pass + class PortError(MasqueError): """ - Exception raised by builder-related functions + Exception raised by port-related functions """ pass + class OneShotError(MasqueError): """ Exception raised when a function decorated with `@oneshot` is called more than once diff --git a/masque/ports.py b/masque/ports.py index 8060616..f12706e 100644 --- a/masque/ports.py +++ b/masque/ports.py @@ -305,11 +305,11 @@ class PortList(metaclass=ABCMeta): if type_conflicts.any(): msg = 'Ports have conflicting types:\n' - for nn, (k, v) in enumerate(connections.items()): + for nn, (kk, vv) in enumerate(connections.items()): if type_conflicts[nn]: - msg += f'{k} | {a_types[nn]}:{b_types[nn]} | {v}\n' msg = ''.join(traceback.format_stack()) + '\n' + msg warnings.warn(msg, stacklevel=2) + msg += f'{kk} | {a_types[nn]}:{b_types[nn]} | {vv}\n' a_offsets = numpy.array([pp.offset for pp in a_ports]) b_offsets = numpy.array([pp.offset for pp in b_ports]) @@ -326,17 +326,17 @@ class PortList(metaclass=ABCMeta): if not numpy.allclose(rotations, 0): rot_deg = numpy.rad2deg(rotations) msg = 'Port orientations do not match:\n' - for nn, (k, v) in enumerate(connections.items()): + for nn, (kk, vv) in enumerate(connections.items()): if not numpy.isclose(rot_deg[nn], 0): - msg += f'{k} | {rot_deg[nn]:g} | {v}\n' + msg += f'{kk} | {rot_deg[nn]:g} | {vv}\n' raise PortError(msg) translations = a_offsets - b_offsets if not numpy.allclose(translations, 0): msg = 'Port translations do not match:\n' - for nn, (k, v) in enumerate(connections.items()): + for nn, (kk, vv) in enumerate(connections.items()): if not numpy.allclose(translations[nn], 0): - msg += f'{k} | {translations[nn]} | {v}\n' + msg += f'{kk} | {translations[nn]} | {vv}\n' raise PortError(msg) for pp in chain(a_names, b_names): @@ -406,7 +406,7 @@ class PortList(metaclass=ABCMeta): map_out_counts = Counter(map_out.values()) map_out_counts[None] = 0 - conflicts_out = {k for k, v in map_out_counts.items() if v > 1} + conflicts_out = {kk for kk, vv in map_out_counts.items() if vv > 1} if conflicts_out: raise PortError(f'Duplicate targets in `map_out`: {conflicts_out}') @@ -438,7 +438,7 @@ class PortList(metaclass=ABCMeta): `set_rotation` must remain `None`. ok_connections: Set of "allowed" ptype combinations. Identical ptypes are always allowed to connect, as is `'unk'` with - any other ptypte. Non-allowed ptype connections will emit a + any other ptypte. Non-allowed ptype connections will log a warning. Order is ignored, i.e. `(a, b)` is equivalent to `(b, a)`. @@ -489,7 +489,7 @@ class PortList(metaclass=ABCMeta): `set_rotation` must remain `None`. ok_connections: Set of "allowed" ptype combinations. Identical ptypes are always allowed to connect, as is `'unk'` with - any other ptypte. Non-allowed ptype connections will emit a + any other ptypte. Non-allowed ptype connections will log a warning. Order is ignored, i.e. `(a, b)` is equivalent to `(b, a)`. @@ -520,11 +520,11 @@ class PortList(metaclass=ABCMeta): 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()): + for nn, (kk, vv) in enumerate(map_in.items()): if type_conflicts[nn]: - msg += f'{k} | {s_types[nn]}:{o_types[nn]} | {v}\n' msg = ''.join(traceback.format_stack()) + '\n' + msg warnings.warn(msg, stacklevel=2) + msg += f'{kk} | {s_types[nn]}:{o_types[nn]} | {vv}\n' rotations = numpy.mod(s_rotations - o_rotations - pi, 2 * pi) if not has_rot.any(): diff --git a/masque/traits/positionable.py b/masque/traits/positionable.py index fd8551b..6779869 100644 --- a/masque/traits/positionable.py +++ b/masque/traits/positionable.py @@ -1,4 +1,4 @@ -from typing import Self, Any +from typing import Self from abc import ABCMeta, abstractmethod import numpy