replaced .format with f strings

This commit is contained in:
Jonathan 2021-07-29 20:28:51 +01:00
parent 192f4436a0
commit 021aab9879
8 changed files with 25 additions and 28 deletions

View file

@ -543,8 +543,6 @@ class AggregateFilter:
def __init__(self, aggregate_filter, bins=None, aggregate_op=None):
self._type = '{}({})'.format(aggregate_op,
aggregate_filter.short_name.lower())
self._type = f'{aggregate_op}({aggregate_filter.short_name.lower()})'
self._bins = None

View file

@ -28,7 +28,7 @@ def check_type(name, value, expected_type, expected_iter_type=None, *, none_ok=F
if not isinstance(value, expected_type):
if isinstance(expected_type, Iterable):
msg = 'Unable to set "{}" to "{}" which is not one of the ' \
msg = f'Unable to set "{}" to "{}" which is not one of the ' \
'following types: "{}"'.format(name, value, ', '.join(
[t.__name__ for t in expected_type]))
else:

View file

@ -251,7 +251,7 @@ class CMFDMesh:
def _display_mesh_warning(self, mesh_type, variable_label):
if self._mesh_type != mesh_type:
warn_msg = ('Setting {variable_label} if mesh type is not set to '
warn_msg = (f'Setting {variable_label} if mesh type is not set to '
'{mesh_type} will have no effect')
warnings.warn(warn_msg, RuntimeWarning)

View file

@ -1111,7 +1111,7 @@ class RealFilter(Filter):
for pair0, pair1 in zip(bins[:-1], bins[1:]):
# Successive pairs should be ordered
if pair1[1] < pair0[1]:
raise ValueError('Values {pair1[1]} and {pair0[1]} appear to '
raise ValueError(f'Values {pair1[1]} and {pair0[1]} appear to '
'be out of order')
def can_merge(self, other):
@ -1414,7 +1414,7 @@ class DistribcellFilter(Filter):
# Make sure there is only 1 bin.
if not len(bins) == 1:
msg =(f'Unable to add bins "{bins}" to a DistribcellFilter since '
msg = (f'Unable to add bins "{bins}" to a DistribcellFilter since '
'only a single distribcell can be used per tally')
raise ValueError(msg)

View file

@ -655,7 +655,7 @@ class StatePoint:
return
if not isinstance(summary, openmc.Summary):
msg = 'Unable to link statepoint with "{summary}" which is not a' \
msg = f'Unable to link statepoint with "{summary}" which is not a' \
'Summary object'
raise ValueError(msg)

View file

@ -352,7 +352,7 @@ class Tally(IDManagerMixin):
visited_nuclides = set()
for nuc in nuclides:
if nuc in visited_nuclides:
msg = ('Unable to add a duplicate nuclide "{nuc}" to Tally ID='
msg = (f'Unable to add a duplicate nuclide "{nuc}" to Tally ID='
'"{self.id}" since duplicate nuclides are not supported '
'in the OpenMC Python API')
raise ValueError(msg)
@ -684,7 +684,7 @@ class Tally(IDManagerMixin):
"""
if not self.can_merge(other):
msg = 'Unable to merge tally ID="{other.id}" with "{self.id}"'
msg = f'Unable to merge tally ID="{other.id}" with "{self.id}"'
raise ValueError(msg)
# Create deep copy of tally to return as merged tally
@ -921,7 +921,7 @@ class Tally(IDManagerMixin):
return test_filter
# If we did not find the Filter, throw an Exception
msg = 'Unable to find filter type "{filter_type}" in Tally ' \
msg = f'Unable to find filter type "{filter_type}" in Tally ' \
'ID="{self.id}"'
raise ValueError(msg)

View file

@ -327,8 +327,7 @@ class Universe(UniverseBase):
for obj, color in colors.items():
if isinstance(color, str):
if color.lower() not in _SVG_COLORS:
raise ValueError("'{}' is not a valid color."
.format(color))
raise ValueError(f"'{color}' is not a valid color.")
colors[obj] = [x/255 for x in
_SVG_COLORS[color.lower()]] + [1.0]
elif len(color) == 3:
@ -402,8 +401,8 @@ class Universe(UniverseBase):
"""
if not isinstance(cell, openmc.Cell):
msg = 'Unable to add a Cell to Universe ID="{0}" since "{1}" is not ' \
'a Cell'.format(self._id, cell)
msg = f'Unable to add a Cell to Universe ID="{self._id}" since ' \
'"{cell}" is not a Cell'
raise TypeError(msg)
cell_id = cell.id
@ -422,8 +421,8 @@ class Universe(UniverseBase):
"""
if not isinstance(cells, Iterable):
msg = 'Unable to add Cells to Universe ID="{0}" since "{1}" is not ' \
'iterable'.format(self._id, cells)
msg = f'Unable to add Cells to Universe ID="{self._id}" since ' \
'"{cells}" is not iterable'
raise TypeError(msg)
for cell in cells:
@ -440,8 +439,8 @@ class Universe(UniverseBase):
"""
if not isinstance(cell, openmc.Cell):
msg = 'Unable to remove a Cell from Universe ID="{0}" since "{1}" is ' \
'not a Cell'.format(self._id, cell)
msg = f'Unable to remove a Cell from Universe ID="{self._id}" ' \
'since "{cell}" is not a Cell'
raise TypeError(msg)
# If the Cell is in the Universe's list of Cells, delete it
@ -492,10 +491,10 @@ class Universe(UniverseBase):
nuclides[name] = (nuclide, density)
else:
raise RuntimeError(
'Volume information is needed to calculate microscopic cross '
'sections for universe {}. This can be done by running a '
'stochastic volume calculation via the '
'openmc.VolumeCalculation object'.format(self.id))
f'Volume information is needed to calculate microscopic cross '
'sections for universe {self.id}. This can be done by running '
'a stochastic volume calculation via the '
'openmc.VolumeCalculation object')
return nuclides
@ -586,10 +585,10 @@ class Universe(UniverseBase):
"""Count the number of instances for each cell in the universe, and
record the count in the :attr:`Cell.num_instances` properties."""
univ_path = path + 'u{}'.format(self.id)
univ_path = path + f'u{self.id}'
for cell in self.cells.values():
cell_path = '{}->c{}'.format(univ_path, cell.id)
cell_path = f'{univ_path}->c{cell.id}'
fill = cell._fill
fill_type = cell.fill_type
@ -619,7 +618,7 @@ class Universe(UniverseBase):
if mat is not None:
mat._num_instances += 1
if not instances_only:
mat._paths.append('{}->m{}'.format(cell_path, mat.id))
mat._paths.append(f'{cell_path}->m{mat.id}')
# Append current path
cell._num_instances += 1

View file

@ -102,9 +102,9 @@ class VolumeCalculation:
if (np.any(np.asarray(lower_left) > ll) or
np.any(np.asarray(upper_right) < ur)):
warnings.warn(
"Specified bounding box is smaller than computed "
"bounding box for cell {}. Volume calculation may "
"be incorrect!".format(c.id))
f"Specified bounding box is smaller than computed "
"bounding box for cell {c.id}. Volume calculation "
"may be incorrect!")
self.lower_left = lower_left
self.upper_right = upper_right