From 39d9b88fa4adb570b6b1d2c9d2af5bd7c48a7325 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Sun, 28 Jul 2024 19:56:57 -0700 Subject: [PATCH] flatten indentation where it makes sense --- masque/builder/pather.py | 16 ++++++++-------- masque/builder/renderpather.py | 2 +- masque/builder/utils.py | 2 +- masque/file/dxf.py | 6 +++--- masque/file/gdsii.py | 2 +- masque/ports.py | 2 +- masque/repetition.py | 3 +-- masque/shapes/polygon.py | 4 ++-- masque/utils/comparisons.py | 4 ++-- masque/utils/pack2d.py | 6 ++---- 10 files changed, 22 insertions(+), 25 deletions(-) diff --git a/masque/builder/pather.py b/masque/builder/pather.py index 7cb434d..17d73b3 100644 --- a/masque/builder/pather.py +++ b/masque/builder/pather.py @@ -658,7 +658,7 @@ class Pather(Builder): if not bound_types: raise BuildError('No bound type specified for mpath') - elif len(bound_types) > 1: + if len(bound_types) > 1: raise BuildError(f'Too many bound types specified for mpath: {bound_types}') bound_type = tuple(bound_types)[0] @@ -672,13 +672,13 @@ class Pather(Builder): # Not a bus, so having a container just adds noise to the layout port_name = tuple(portspec)[0] return self.path(port_name, ccw, extensions[port_name], tool_port_names=tool_port_names, **kwargs) - else: - bld = Pather.interface(source=ports, library=self.library, tools=self.tools) - for port_name, length in extensions.items(): - bld.path(port_name, ccw, length, tool_port_names=tool_port_names, **kwargs) - name = self.library.get_name(base_name) - self.library[name] = bld.pattern - return self.plug(Abstract(name, bld.pattern.ports), {sp: 'in_' + sp for sp in ports.keys()}) # TODO safe to use 'in_'? + + bld = Pather.interface(source=ports, library=self.library, tools=self.tools) + for port_name, length in extensions.items(): + bld.path(port_name, ccw, length, tool_port_names=tool_port_names, **kwargs) + name = self.library.get_name(base_name) + self.library[name] = bld.pattern + return self.plug(Abstract(name, bld.pattern.ports), {sp: 'in_' + sp for sp in ports}) # TODO safe to use 'in_'? # TODO def bus_join()? diff --git a/masque/builder/renderpather.py b/masque/builder/renderpather.py index 6c42519..11759a5 100644 --- a/masque/builder/renderpather.py +++ b/masque/builder/renderpather.py @@ -561,7 +561,7 @@ class RenderPather(PortList): if not bound_types: raise BuildError('No bound type specified for mpath') - elif len(bound_types) > 1: + if len(bound_types) > 1: raise BuildError(f'Too many bound types specified for mpath: {bound_types}') bound_type = tuple(bound_types)[0] diff --git a/masque/builder/utils.py b/masque/builder/utils.py index ae2f564..fe30cf4 100644 --- a/masque/builder/utils.py +++ b/masque/builder/utils.py @@ -113,7 +113,7 @@ def ell( is_horizontal = numpy.isclose(rotations[0] % pi, 0) if bound_type in ('ymin', 'ymax') and is_horizontal: raise BuildError(f'Asked for {bound_type} position but ports are pointing along the x-axis!') - elif bound_type in ('xmin', 'xmax') and not is_horizontal: + if bound_type in ('xmin', 'xmax') and not is_horizontal: raise BuildError(f'Asked for {bound_type} position but ports are pointing along the y-axis!') direction = rotations[0] + pi # direction we want to travel in (+pi relative to port) diff --git a/masque/file/dxf.py b/masque/file/dxf.py index e665e89..5b5fabc 100644 --- a/masque/file/dxf.py +++ b/masque/file/dxf.py @@ -220,11 +220,11 @@ def _read_block(block) -> tuple[str, Pattern]: if points.shape[1] == 2: raise PatternError('Invalid or unimplemented polygon?') - #shape = Polygon() - elif points.shape[1] > 2: + + if points.shape[1] > 2: if (points[0, 2] != points[:, 2]).any(): raise PatternError('PolyLine has non-constant width (not yet representable in masque!)') - elif points.shape[1] == 4 and (points[:, 3] != 0).any(): + if points.shape[1] == 4 and (points[:, 3] != 0).any(): raise PatternError('LWPolyLine has bulge (not yet representable in masque!)') width = points[0, 2] diff --git a/masque/file/gdsii.py b/masque/file/gdsii.py index 78c1b1a..d37a634 100644 --- a/masque/file/gdsii.py +++ b/masque/file/gdsii.py @@ -604,7 +604,7 @@ def load_libraryfile( else: gz_stream = gzip.open(path, mode='rb') stream = io.BufferedReader(gz_stream) # type: ignore - else: + else: # noqa: PLR5501 if mmap: base_stream = open(path, mode='rb', buffering=0) stream = mmap.mmap(base_stream.fileno(), 0, access=mmap.ACCESS_READ) # type: ignore diff --git a/masque/ports.py b/masque/ports.py index 69e5399..86eadc4 100644 --- a/masque/ports.py +++ b/masque/ports.py @@ -181,7 +181,7 @@ class PortList(metaclass=ABCMeta): """ if isinstance(key, str): return self.ports[key] - else: + else: # noqa: RET505 return {k: self.ports[k] for k in key} def __contains__(self, key: str) -> NoReturn: diff --git a/masque/repetition.py b/masque/repetition.py index 2272770..972f3b7 100644 --- a/masque/repetition.py +++ b/masque/repetition.py @@ -101,8 +101,7 @@ class Grid(Repetition): if b_vector is None: if b_count > 1: raise PatternError('Repetition has b_count > 1 but no b_vector') - else: - b_vector = numpy.array([0.0, 0.0]) + b_vector = numpy.array([0.0, 0.0]) if a_count < 1: raise PatternError(f'Repetition has too-small a_count: {a_count}') diff --git a/masque/shapes/polygon.py b/masque/shapes/polygon.py index d36e5b5..d07ed92 100644 --- a/masque/shapes/polygon.py +++ b/masque/shapes/polygon.py @@ -253,7 +253,7 @@ class Polygon(Shape): lx = 2 * (xmax - xctr) else: raise PatternError('Two of xmin, xctr, xmax, lx must be None!') - else: + else: # noqa: PLR5501 if xctr is not None: pass elif xmax is None: @@ -283,7 +283,7 @@ class Polygon(Shape): ly = 2 * (ymax - yctr) else: raise PatternError('Two of ymin, yctr, ymax, ly must be None!') - else: + else: # noqa: PLR5501 if yctr is not None: pass elif ymax is None: diff --git a/masque/utils/comparisons.py b/masque/utils/comparisons.py index fe462b5..5de8f4a 100644 --- a/masque/utils/comparisons.py +++ b/masque/utils/comparisons.py @@ -12,7 +12,7 @@ def annotation2key(aaa: int | float | str) -> tuple[bool, Any]: def annotations_lt(aa: annotations_t, bb: annotations_t) -> bool: if aa is None: return bb is not None - elif bb is None: + elif bb is None: # noqa: RET505 return False if len(aa) != len(bb): @@ -38,7 +38,7 @@ def annotations_lt(aa: annotations_t, bb: annotations_t) -> bool: def annotations_eq(aa: annotations_t, bb: annotations_t) -> bool: if aa is None: return bb is None - elif bb is None: + elif bb is None: # noqa: RET505 return False if len(aa) != len(bb): diff --git a/masque/utils/pack2d.py b/masque/utils/pack2d.py index 50b78d5..7405406 100644 --- a/masque/utils/pack2d.py +++ b/masque/utils/pack2d.py @@ -70,8 +70,7 @@ def maxrects_bssf( if allow_rejects: rejected_inds.add(rect_ind) continue - else: - raise MasqueError(f'Failed to find a suitable location for rectangle {rect_ind}') + raise MasqueError(f'Failed to find a suitable location for rectangle {rect_ind}') # Read out location loc = regions[rr, :2] @@ -161,8 +160,7 @@ def guillotine_bssf_sas( if allow_rejects: rejected_inds.add(rect_ind) continue - else: - raise MasqueError(f'Failed to find a suitable location for rectangle {rect_ind}') + raise MasqueError(f'Failed to find a suitable location for rectangle {rect_ind}') # Read out location loc = regions[rr, :2]