Skip to content

Commit d38e59b

Browse files
committed
docs: Pass fstrings in dense after rebase
1 parent d36f063 commit d38e59b

File tree

1 file changed

+39
-40
lines changed

1 file changed

+39
-40
lines changed

devito/types/dense.py

+39-40
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ def __init_finalize__(self, *args, function=None, **kwargs):
111111
# case `self._data is None`
112112
self.data
113113
else:
114-
raise ValueError("`initializer` must be callable or buffer, not %s"
115-
% type(initializer))
114+
raise ValueError(f"`initializer` must be callable or buffer, "
115+
f"not {type(initializer)}")
116116

117117
_subs = Differentiable._subs
118118

@@ -125,8 +125,8 @@ def wrapper(self):
125125
# Aliasing Functions must not allocate data
126126
return
127127

128-
debug("Allocating host memory for %s%s [%s]"
129-
% (self.name, self.shape_allocated, humanbytes(self.nbytes)))
128+
debug(f"Allocating host memory for {self.name}{self.shape_allocated} "
129+
f"[{humanbytes(self.nbytes)}]")
130130

131131
# Clear up both SymPy and Devito caches to drop unreachable data
132132
CacheManager.clear(force=False)
@@ -176,8 +176,8 @@ def __coefficients_setup__(self, **kwargs):
176176
if coeffs == 'symbolic':
177177
deprecations.symbolic_warn
178178
else:
179-
raise ValueError("coefficients must be one of %s"
180-
" not %s" % (str(fd_weights_registry), coeffs))
179+
raise ValueError(f"coefficients must be one of {fd_weights_registry} "
180+
f"not {coeffs}")
181181
return coeffs
182182

183183
def __staggered_setup__(self, **kwargs):
@@ -352,12 +352,12 @@ def _size_outhalo(self):
352352

353353
if self._distributor.is_parallel and (any(left) > 0 or any(right)) > 0:
354354
try:
355-
warning_msg = """A space order of {0} and a halo size of {1} has been
356-
set but the current rank ({2}) has a domain size of
357-
only {3}""".format(self._space_order,
358-
max(self._size_inhalo),
359-
self._distributor.myrank,
360-
min(self.grid.shape_local))
355+
warning_msg = (
356+
f"A space order of {self._space_order} and a halo size of "
357+
f"{max(self._size_inhalo)} has been set but the current rank "
358+
f"({self._distributor.myrank}) has a domain size of only "
359+
f"{min(self.grid.shape_local)}"
360+
)
361361
if not self._distributor.is_boundary_rank:
362362
warning(warning_msg)
363363
else:
@@ -768,7 +768,7 @@ def _C_get_field(self, region, dim, side=None):
768768
offset = 0
769769
size = ffp(self._C_field_size, self._C_make_index(dim))
770770
else:
771-
raise ValueError("Unknown region `%s`" % str(region))
771+
raise ValueError(f"Unknown region `{region}`")
772772

773773
return RegionMeta(offset, size)
774774

@@ -781,8 +781,8 @@ def _halo_exchange(self):
781781
# Nothing to do
782782
return
783783
if MPI.COMM_WORLD.size > 1 and self._distributor is None:
784-
raise RuntimeError("`%s` cannot perform a halo exchange as it has "
785-
"no Grid attached" % self.name)
784+
raise RuntimeError(f"`{self.name}` cannot perform a halo exchange "
785+
f"as it has no Grid attached")
786786

787787
neighborhood = self._distributor.neighborhood
788788
comm = self._distributor.comm
@@ -874,17 +874,16 @@ def _arg_check(self, args, intervals, **kwargs):
874874
If an incompatibility is detected.
875875
"""
876876
if self.name not in args:
877-
raise InvalidArgument("No runtime value for `%s`" % self.name)
877+
raise InvalidArgument(f"No runtime value for `{self.name}`")
878878

879879
data = args[self.name]
880880

881881
if len(data.shape) != self.ndim:
882-
raise InvalidArgument("Shape %s of runtime value `%s` does not match "
883-
"dimensions %s" %
884-
(data.shape, self.name, self.dimensions))
882+
raise InvalidArgument(f"Shape {data.shape} of runtime value `{self.name}` "
883+
f"does not match dimensions {self.dimensions}")
885884
if data.dtype != self.dtype:
886-
warning("Data type %s of runtime value `%s` does not match the "
887-
"Function data type %s" % (data.dtype, self.name, self.dtype))
885+
warning(f"Data type {data.dtype} of runtime value `{self.name}` "
886+
f"does not match the Function data type {self.dtype}")
888887

889888
# Check each Dimension for potential OOB accesses
890889
for i, s in zip(self.dimensions, data.shape):
@@ -894,11 +893,11 @@ def _arg_check(self, args, intervals, **kwargs):
894893
args.options['linearize'] and \
895894
self.is_regular and \
896895
data.size - 1 >= np.iinfo(np.int32).max:
897-
raise InvalidArgument("`%s`, with its %d elements, is too big for "
898-
"int32 pointer arithmetic. Consider using the "
899-
"'index-mode=int64' option, the save=Buffer(..) "
900-
"API (TimeFunction only), or domain "
901-
"decomposition via MPI" % (self.name, data.size))
896+
raise InvalidArgument(f"`{self.name}`, with its {data.size} elements, "
897+
"is too big for int32 pointer arithmetic."
898+
"Consider using the 'index-mode=int64' option, "
899+
"the save=Buffer(..) (TimeFunction only), or domain "
900+
"decomposition via MPI")
902901

903902
def _arg_finalize(self, args, alias=None):
904903
key = alias or self
@@ -1134,9 +1133,8 @@ def __shape_setup__(cls, **kwargs):
11341133
if d in grid.dimensions:
11351134
size = grid.dimension_map[d]
11361135
if size.glb != s and s is not None:
1137-
raise ValueError("Dimension `%s` is given size `%d`, "
1138-
"while `grid` says `%s` has size `%d` "
1139-
% (d, s, d, size.glb))
1136+
raise ValueError(f"Dimension `{d}` is given size `{s}`, "
1137+
f"while `grid` says `{d}` has size `{size.glb}`")
11401138
else:
11411139
loc_shape.append(size.loc)
11421140
else:
@@ -1192,7 +1190,7 @@ def __padding_setup__(self, **kwargs):
11921190
padding = tuple((0, i) if isinstance(i, int) else i for i in padding)
11931191

11941192
else:
1195-
raise TypeError("`padding` must be int or %d-tuple of ints" % self.ndim)
1193+
raise TypeError(f"`padding` must be int or {self.ndim}-tuple of ints")
11961194
return DimensionTuple(*padding, getters=self.dimensions)
11971195

11981196
@property
@@ -1438,7 +1436,7 @@ def __shape_setup__(cls, **kwargs):
14381436
elif isinstance(save, int):
14391437
shape.insert(cls._time_position, save)
14401438
else:
1441-
raise TypeError("`save` can be None, int or Buffer, not %s" % type(save))
1439+
raise TypeError(f"`save` can be None, int or Buffer, not {type(save)}")
14421440
elif dimensions is None:
14431441
raise TypeError("`dimensions` required if both `grid` and "
14441442
"`shape` are provided")
@@ -1502,9 +1500,10 @@ def _arg_check(self, args, intervals, **kwargs):
15021500

15031501
key_time_size = args[self.name].shape[self._time_position]
15041502
if self._time_buffering and self._time_size != key_time_size:
1505-
raise InvalidArgument("Expected `time_size=%d` for runtime "
1506-
"value `%s`, found `%d` instead"
1507-
% (self._time_size, self.name, key_time_size))
1503+
raise InvalidArgument(
1504+
f"Expected `time_size={self._time_size}` for runtime value "
1505+
f"`{self.name}`, found `{key_time_size}` instead"
1506+
)
15081507

15091508

15101509
class SubFunction(Function):
@@ -1533,8 +1532,8 @@ def _arg_values(self, **kwargs):
15331532
if self._parent is not None and self.parent.name not in kwargs:
15341533
return self._parent._arg_defaults(alias=self._parent).reduce_all()
15351534
elif self.name in kwargs:
1536-
raise RuntimeError("`%s` is a SubFunction, so it can't be assigned "
1537-
"a value dynamically" % self.name)
1535+
raise RuntimeError(f"`{self.name}` is a SubFunction, so it can't "
1536+
"be assigned a value dynamically")
15381537
else:
15391538
return self._arg_defaults(alias=self)
15401539

@@ -1678,8 +1677,8 @@ def make(self, shape=None, initializer=None, allocator=None, **kwargs):
16781677
for n, i in enumerate(self.shape):
16791678
v = i.subs(args)
16801679
if not v.is_Integer:
1681-
raise ValueError("Couldn't resolve `shape[%d]=%s` with the given "
1682-
"kwargs (obtained: `%s`)" % (n, i, v))
1680+
raise ValueError(f"Couldn't resolve `shape[{n}]={i}` with the given "
1681+
f"kwargs (obtained: `{v}`)")
16831682
shape.append(int(v))
16841683
shape = tuple(shape)
16851684
elif len(shape) != self.ndim:
@@ -1706,6 +1705,6 @@ def _arg_values(self, **kwargs):
17061705
# Set new values and re-derive defaults
17071706
return new._arg_defaults().reduce_all()
17081707
else:
1709-
raise InvalidArgument("Illegal runtime value for `%s`" % self.name)
1708+
raise InvalidArgument(f"Illegal runtime value for `{self.name}`")
17101709
else:
1711-
raise InvalidArgument("TempFunction `%s` lacks override" % self.name)
1710+
raise InvalidArgument(f"TempFunction `{self.name}` lacks override")

0 commit comments

Comments
 (0)