diff --git a/openmc/arithmetic.py b/openmc/arithmetic.py index c565cda0db..c723fb3e99 100644 --- a/openmc/arithmetic.py +++ b/openmc/arithmetic.py @@ -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 diff --git a/openmc/checkvalue.py b/openmc/checkvalue.py index 3c76890f75..09ee4e400e 100644 --- a/openmc/checkvalue.py +++ b/openmc/checkvalue.py @@ -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: diff --git a/openmc/cmfd.py b/openmc/cmfd.py index 52665035f3..f9bd83f9bc 100644 --- a/openmc/cmfd.py +++ b/openmc/cmfd.py @@ -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) diff --git a/openmc/filter.py b/openmc/filter.py index fd1be41e3b..a9e9f2433e 100644 --- a/openmc/filter.py +++ b/openmc/filter.py @@ -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) diff --git a/openmc/statepoint.py b/openmc/statepoint.py index cd8651ea3b..894730cbe9 100644 --- a/openmc/statepoint.py +++ b/openmc/statepoint.py @@ -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) diff --git a/openmc/tallies.py b/openmc/tallies.py index bdeffa8f55..33d059f17c 100644 --- a/openmc/tallies.py +++ b/openmc/tallies.py @@ -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) diff --git a/openmc/universe.py b/openmc/universe.py index 5cfb985793..a8b6d51e98 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -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 diff --git a/openmc/volume.py b/openmc/volume.py index 7a9ef17371..7c86f1fe9e 100644 --- a/openmc/volume.py +++ b/openmc/volume.py @@ -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