Skip to content

Commit 0cca59e

Browse files
author
Sourcery AI
committed
'Refactored by Sourcery'
1 parent 0c4974a commit 0cca59e

File tree

7 files changed

+193
-304
lines changed

7 files changed

+193
-304
lines changed

klayout_pyxs/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def _poly_repr(self):
8383
8484
This is useful when printing a list of Polygons
8585
"""
86-
return '{} pts: '.format(self.num_points()) + self.__str__()
86+
return f'{self.num_points()} pts: ' + self.__str__()
8787

8888

8989
Polygon.__repr__ = _poly_repr

klayout_pyxs/geometry_2d.py

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,9 @@ def safe_boolean_to_polygon(self, pa, pb, mode, rh=True, mc=True):
9090
elif mode == self.ModeAnd: # either pa and pb is empty, mode AND
9191
return [] # will be empty
9292
elif mode == self.ModeOr:
93-
if n_pa > 0:
94-
return pa
95-
else:
96-
return pb
93+
return pa if n_pa > 0 else pb
9794
elif mode == self.ModeXor:
98-
if n_pa > 0:
99-
return pa
100-
else:
101-
return pb
95+
return pa if n_pa > 0 else pb
10296
elif mode == self.ModeANotB:
10397
return pa
10498
elif mode == self.ModeBNotA:
@@ -139,10 +133,10 @@ def size_p2p(self, polygons, dx, dy=0, mode=2, rh=True, mc=True):
139133
The output polygons
140134
141135
"""
142-
info(' polys = {}'.format(polygons))
143-
info(' dx = {}, dy = {}'.format(dx, dy))
136+
info(f' polys = {polygons}')
137+
info(f' dx = {dx}, dy = {dy}')
144138
res = super(EdgeProcessor, self).size_p2p(polygons, dx, dy, mode, rh, mc)
145-
info(' EP.size_p2p().res = {}'.format(res))
139+
info(f' EP.size_p2p().res = {res}')
146140
return res
147141

148142

@@ -181,31 +175,38 @@ def parse_grow_etch_args(method, material_cls, into=(), through=(), on=(),
181175
for i in into:
182176
# should be MaterialData @@@
183177
if not isinstance(i, material_cls):
184-
raise TypeError("'{}' method: 'into' expects a material "
185-
"parameter or an array of such. {} is given"
186-
.format(method, type(i)))
178+
raise TypeError(
179+
f"'{method}' method: 'into' expects a material parameter or an array of such. {type(i)} is given"
180+
)
181+
187182
if on:
188183
on = make_iterable(on)
189184
for i in on:
190185
# should be MaterialData @@@
191186
if not isinstance(i, material_cls):
192-
raise TypeError("'{}' method: 'on' expects a material "
193-
"parameter or an array of such".format(method))
187+
raise TypeError(
188+
f"'{method}' method: 'on' expects a material parameter or an array of such"
189+
)
190+
194191
if through:
195192
through = make_iterable(through)
196193
for i in through:
197194
# should be MaterialData @@@
198195
if not isinstance(i, material_cls):
199-
raise TypeError("'{}' method: 'through' expects a material "
200-
"parameter or an array of such".format(method))
196+
raise TypeError(
197+
f"'{method}' method: 'through' expects a material parameter or an array of such"
198+
)
199+
201200

202201
if on and (through or into):
203202
raise ValueError("'on' option cannot be combined with 'into' or "
204203
"'through' option")
205204

206205
if mode not in ('round', 'square', 'octagon'):
207-
raise ValueError("'{}' method: 'mode' should be 'round', 'square' or "
208-
"'octagon'".format(method))
206+
raise ValueError(
207+
f"'{method}' method: 'mode' should be 'round', 'square' or 'octagon'"
208+
)
209+
209210

210211
return into, through, on, mode
211212

@@ -244,7 +245,7 @@ def dup(self):
244245
def __str__(self):
245246
n_poly = self.n_poly
246247

247-
s = 'LayoutData (n_polygons = {})'.format(n_poly)
248+
s = f'LayoutData (n_polygons = {n_poly})'
248249

249250
if n_poly > 0:
250251
s += ':'
@@ -254,8 +255,7 @@ def __str__(self):
254255
return s
255256

256257
def __repr__(self):
257-
s = '<LayoutData (n_polygons = {})>'.format(self.n_poly)
258-
return s
258+
return f'<LayoutData (n_polygons = {self.n_poly})>'
259259

260260
@property
261261
def data(self):
@@ -340,16 +340,16 @@ def load(self, layout, cell, box, layer_spec):
340340
layer_spec : str
341341
layer to be used
342342
"""
343-
info('LD.load(..., box={}, layer_spec={})'.format(box, layer_spec))
343+
info(f'LD.load(..., box={box}, layer_spec={layer_spec})')
344344

345345
ls = string_to_layer_info(layer_spec)
346346

347347
# look up the layer index with a given layer_spec in the current layout
348348
layer_index = None
349349
for li in layout.layer_indices():
350-
info(" li = {}".format(li))
350+
info(f" li = {li}")
351351
if layout.get_info(li).is_equivalent(ls):
352-
info(" layer_index = {}".format(li))
352+
info(f" layer_index = {li}")
353353
layer_index = li
354354
break
355355

@@ -367,11 +367,11 @@ def load(self, layout, cell, box, layer_spec):
367367
shape_iter.next()
368368

369369
n_poly = self.n_poly
370-
info(' loaded polygon count: {}'.format(n_poly))
370+
info(f' loaded polygon count: {n_poly}')
371371
if n_poly > 0:
372372
info(' loaded polygons:')
373373
for pi in range(min(2, n_poly)):
374-
info(' {}'.format(self._polygons[pi]))
374+
info(f' {self._polygons[pi]}')
375375

376376
info('LD.load()\n')
377377

@@ -465,11 +465,13 @@ def sized(self, dx, dy=None):
465465
ld : LayoutData
466466
"""
467467
dy = dx if dy is None else dy
468-
ld = self.upcast(self._ep.size_p2p(self._polygons,
469-
int_floor(dx / self._xs.dbu + 0.5),
470-
int_floor(dy / self._xs.dbu + 0.5)
471-
))
472-
return ld
468+
return self.upcast(
469+
self._ep.size_p2p(
470+
self._polygons,
471+
int_floor(dx / self._xs.dbu + 0.5),
472+
int_floor(dy / self._xs.dbu + 0.5),
473+
)
474+
)
473475

474476
def sub(self, other):
475477
""" Substract another list of polygons.
@@ -539,9 +541,9 @@ def _get_polygons(l):
539541
elif isinstance(l, (tuple, list)):
540542
return l
541543
else:
542-
raise TypeError('l should be either an instance of LayoutData or '
543-
'a list of Polygon. {} is given.'
544-
.format(type(l)))
544+
raise TypeError(
545+
f'l should be either an instance of LayoutData or a list of Polygon. {type(l)} is given.'
546+
)
545547

546548

547549
class MaskData(LayoutData):
@@ -569,8 +571,8 @@ def __init__(self, air_polygons, mask_polygons, xs):
569571
self._air_polygons = air_polygons
570572
self._mask_polygons = mask_polygons
571573

572-
info('air_polygons = {}'.format(air_polygons))
573-
info('mask_polygons = {}'.format(mask_polygons))
574+
info(f'air_polygons = {air_polygons}')
575+
info(f'mask_polygons = {mask_polygons}')
574576
info('Success!')
575577

576578
def upcast(self, polygons):
@@ -583,8 +585,8 @@ def __str__(self):
583585
n_air_poly = self.n_air_poly
584586
n_mask_poly = self.n_mask_poly
585587

586-
s = '{} (n_air_polygons={}, n_mask_polygons={})'.format(
587-
self.__class__.__name__, n_air_poly, n_mask_poly)
588+
s = f'{self.__class__.__name__} (n_air_polygons={n_air_poly}, n_mask_polygons={n_mask_poly})'
589+
588590

589591
if n_mask_poly > 0:
590592
s += ':'
@@ -616,9 +618,7 @@ def n_mask_poly(self):
616618
return len(self._mask_polygons)
617619

618620
def __repr__(self):
619-
s = '<MaskData (delta={}, n_air_polygons={}, n_mask_polygons={})>' \
620-
.format(self._delta, self.n_air_poly, self.n_mask_poly)
621-
return s
621+
return f'<MaskData (delta={self._delta}, n_air_polygons={self.n_air_poly}, n_mask_polygons={self.n_mask_poly})>'
622622

623623
@print_info(False)
624624
def grow(self, z, xy=0.0, into=(), through=(), on=(), mode='square',
@@ -661,11 +661,11 @@ def grow(self, z, xy=0.0, into=(), through=(), on=(), mode='square',
661661
662662
"""
663663
# parse the arguments
664-
info(' into={}'.format(into))
664+
info(f' into={into}')
665665
into, through, on, mode = parse_grow_etch_args(
666666
'grow', MaterialData, into=into, through=through, on=on, mode=mode)
667667

668-
info(' into={}'.format(into))
668+
info(f' into={into}')
669669
# produce the geometry of the new material
670670
d = self.produce_geom('grow', xy, z,
671671
into, through, on,

0 commit comments

Comments
 (0)