@@ -90,15 +90,9 @@ def safe_boolean_to_polygon(self, pa, pb, mode, rh=True, mc=True):
90
90
elif mode == self .ModeAnd : # either pa and pb is empty, mode AND
91
91
return [] # will be empty
92
92
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
97
94
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
102
96
elif mode == self .ModeANotB :
103
97
return pa
104
98
elif mode == self .ModeBNotA :
@@ -139,10 +133,10 @@ def size_p2p(self, polygons, dx, dy=0, mode=2, rh=True, mc=True):
139
133
The output polygons
140
134
141
135
"""
142
- info (' polys = {}' . format ( polygons ) )
143
- info (' dx = {}, dy = {}' . format ( dx , dy ) )
136
+ info (f ' polys = { polygons } ' )
137
+ info (f ' dx = { dx } , dy = { dy } ' )
144
138
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 } ' )
146
140
return res
147
141
148
142
@@ -181,31 +175,38 @@ def parse_grow_etch_args(method, material_cls, into=(), through=(), on=(),
181
175
for i in into :
182
176
# should be MaterialData @@@
183
177
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
+
187
182
if on :
188
183
on = make_iterable (on )
189
184
for i in on :
190
185
# should be MaterialData @@@
191
186
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
+
194
191
if through :
195
192
through = make_iterable (through )
196
193
for i in through :
197
194
# should be MaterialData @@@
198
195
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
+
201
200
202
201
if on and (through or into ):
203
202
raise ValueError ("'on' option cannot be combined with 'into' or "
204
203
"'through' option" )
205
204
206
205
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
+
209
210
210
211
return into , through , on , mode
211
212
@@ -244,7 +245,7 @@ def dup(self):
244
245
def __str__ (self ):
245
246
n_poly = self .n_poly
246
247
247
- s = 'LayoutData (n_polygons = {})' . format ( n_poly )
248
+ s = f 'LayoutData (n_polygons = { n_poly } )'
248
249
249
250
if n_poly > 0 :
250
251
s += ':'
@@ -254,8 +255,7 @@ def __str__(self):
254
255
return s
255
256
256
257
def __repr__ (self ):
257
- s = '<LayoutData (n_polygons = {})>' .format (self .n_poly )
258
- return s
258
+ return f'<LayoutData (n_polygons = { self .n_poly } )>'
259
259
260
260
@property
261
261
def data (self ):
@@ -340,16 +340,16 @@ def load(self, layout, cell, box, layer_spec):
340
340
layer_spec : str
341
341
layer to be used
342
342
"""
343
- info ('LD.load(..., box={}, layer_spec={})' . format ( box , layer_spec ) )
343
+ info (f 'LD.load(..., box={ box } , layer_spec={ layer_spec } )' )
344
344
345
345
ls = string_to_layer_info (layer_spec )
346
346
347
347
# look up the layer index with a given layer_spec in the current layout
348
348
layer_index = None
349
349
for li in layout .layer_indices ():
350
- info (" li = {}" . format ( li ) )
350
+ info (f " li = { li } " )
351
351
if layout .get_info (li ).is_equivalent (ls ):
352
- info (" layer_index = {}" . format ( li ) )
352
+ info (f " layer_index = { li } " )
353
353
layer_index = li
354
354
break
355
355
@@ -367,11 +367,11 @@ def load(self, layout, cell, box, layer_spec):
367
367
shape_iter .next ()
368
368
369
369
n_poly = self .n_poly
370
- info (' loaded polygon count: {}' . format ( n_poly ) )
370
+ info (f ' loaded polygon count: { n_poly } ' )
371
371
if n_poly > 0 :
372
372
info (' loaded polygons:' )
373
373
for pi in range (min (2 , n_poly )):
374
- info (' {}' . format ( self ._polygons [pi ]) )
374
+ info (f ' { self ._polygons [pi ]} ' )
375
375
376
376
info ('LD.load()\n ' )
377
377
@@ -465,11 +465,13 @@ def sized(self, dx, dy=None):
465
465
ld : LayoutData
466
466
"""
467
467
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
+ )
473
475
474
476
def sub (self , other ):
475
477
""" Substract another list of polygons.
@@ -539,9 +541,9 @@ def _get_polygons(l):
539
541
elif isinstance (l , (tuple , list )):
540
542
return l
541
543
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
+ )
545
547
546
548
547
549
class MaskData (LayoutData ):
@@ -569,8 +571,8 @@ def __init__(self, air_polygons, mask_polygons, xs):
569
571
self ._air_polygons = air_polygons
570
572
self ._mask_polygons = mask_polygons
571
573
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 } ' )
574
576
info ('Success!' )
575
577
576
578
def upcast (self , polygons ):
@@ -583,8 +585,8 @@ def __str__(self):
583
585
n_air_poly = self .n_air_poly
584
586
n_mask_poly = self .n_mask_poly
585
587
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
+
588
590
589
591
if n_mask_poly > 0 :
590
592
s += ':'
@@ -616,9 +618,7 @@ def n_mask_poly(self):
616
618
return len (self ._mask_polygons )
617
619
618
620
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 } )>'
622
622
623
623
@print_info (False )
624
624
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',
661
661
662
662
"""
663
663
# parse the arguments
664
- info (' into={}' . format ( into ) )
664
+ info (f ' into={ into } ' )
665
665
into , through , on , mode = parse_grow_etch_args (
666
666
'grow' , MaterialData , into = into , through = through , on = on , mode = mode )
667
667
668
- info (' into={}' . format ( into ) )
668
+ info (f ' into={ into } ' )
669
669
# produce the geometry of the new material
670
670
d = self .produce_geom ('grow' , xy , z ,
671
671
into , through , on ,
0 commit comments