Skip to content

Commit c8c2ccf

Browse files
mlouboutclaude
andcommitted
misc: Fix flake8 violations in f-string conversion
Address line length (E501), indentation (E127), and syntax (E999) issues introduced during the % to f-string conversion. Fixed f-string syntax errors by extracting backslash expressions to variables. All modified files now pass flake8 checks. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 7ad4710 commit c8c2ccf

File tree

8 files changed

+29
-19
lines changed

8 files changed

+29
-19
lines changed

devito/arch/compiler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,9 @@ def __init_finalize__(self, **kwargs):
681681
proc_link_flags.extend(['-Xcompiler', '-pthread'])
682682
elif i.startswith('-Wl'):
683683
# E.g., `-Wl,-rpath` -> `-Xcompiler "-Wl\,-rpath"`
684+
escaped_i = i.replace(",", r"\\,")
684685
proc_link_flags.extend([
685-
'-Xcompiler', f'"{i.replace(",", r"\\,")}"'
686+
'-Xcompiler', f'"{escaped_i}"'
686687
])
687688
else:
688689
proc_link_flags.append(i)

devito/data/allocators.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,11 @@ def __init__(self, numpy_array):
375375

376376
def alloc(self, shape, dtype, padding=0):
377377
assert shape == self.numpy_array.shape, \
378-
f"Provided array has shape {str(self.numpy_array.shape)}. Expected {str(shape)}"
378+
(f"Provided array has shape {str(self.numpy_array.shape)}. "
379+
f"Expected {str(shape)}")
379380
assert dtype == self.numpy_array.dtype, \
380-
f"Provided array has dtype {str(self.numpy_array.dtype)}. Expected {str(dtype)}"
381+
(f"Provided array has dtype {str(self.numpy_array.dtype)}. "
382+
f"Expected {str(dtype)}")
381383

382384
return (self.numpy_array, None)
383385

devito/finite_differences/differentiable.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ def div(self, shift=None, order=None, method='FD', **kwargs):
353353
shift_x0 = make_shift_x0(shift, (len(space_dims),))
354354
order = order or self.space_order
355355
return Add(*[getattr(self, f'd{d.name}')(x0=shift_x0(shift, d, None, i),
356-
fd_order=order, method=method, w=w)
356+
fd_order=order, method=method, w=w)
357357
for i, d in enumerate(space_dims)])
358358

359359
def grad(self, shift=None, order=None, method='FD', **kwargs):
@@ -381,7 +381,7 @@ def grad(self, shift=None, order=None, method='FD', **kwargs):
381381
order = order or self.space_order
382382
w = kwargs.get('weights', kwargs.get('w'))
383383
comps = [getattr(self, f'd{d.name}')(x0=shift_x0(shift, d, None, i),
384-
fd_order=order, method=method, w=w)
384+
fd_order=order, method=method, w=w)
385385
for i, d in enumerate(space_dims)]
386386
vec_func = VectorTimeFunction if self.is_TimeDependent else VectorFunction
387387
return vec_func(name=f'grad_{self.name}', time_order=self.time_order,

devito/ir/support/basic.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,8 @@ def __repr__(self):
10511051
continue
10521052
first = f"{tuple.__repr__(r[0])}"
10531053
shifted = "\n".join(f"{pad}{tuple.__repr__(j)}" for j in r[1:])
1054-
shifted = f"{'\n' if shifted else ''}{shifted}"
1054+
newline_prefix = '\n' if shifted else ''
1055+
shifted = f"{newline_prefix}{shifted}"
10551056
reads[i] = first + shifted
10561057
writes = [self.getwrites(i) for i in tracked]
10571058
for i, w in enumerate(list(writes)):
@@ -1060,7 +1061,7 @@ def __repr__(self):
10601061
continue
10611062
first = f"{tuple.__repr__(w[0])}"
10621063
shifted = "\n".join(f"{pad}{tuple.__repr__(j)}" for j in w[1:])
1063-
shifted = f"{'\n' if shifted else ''}{shifted}"
1064+
shifted = f"{chr(10) if shifted else ''}{shifted}"
10641065
writes[i] = f'\033[1;37;31m{first + shifted}\033[0m'
10651066
return "\n".join([out.format(i.name, w, '', r)
10661067
for i, r, w in zip(tracked, reads, writes)])

devito/operations/interpolators.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ def operation(self, **kwargs):
122122
implicit_dims=self.implicit_dims)
123123

124124
def __repr__(self):
125-
return f"Interpolation({repr(self.expr)} into {repr(self.interpolator.sfunction)})"
125+
return (f"Interpolation({repr(self.expr)} into "
126+
f"{repr(self.interpolator.sfunction)})")
126127

127128

128129
class Injection(UnevaluatedSparseOperation):

devito/parameters.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ def wrapper(self, key, value):
5656
def _check_key_deprecation(func):
5757
def wrapper(self, key, value=None):
5858
if key in self._deprecated:
59-
warning(f"Trying to access deprecated config `{key}`. Using `{self._deprecated[key]}` instead")
59+
warning(f"Trying to access deprecated config `{key}`. "
60+
f"Using `{self._deprecated[key]}` instead")
6061
key = self._deprecated[key]
6162
return func(self, key, value)
6263
return wrapper

devito/types/dense.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ def wrapper(self):
122122
# Aliasing Functions must not allocate data
123123
return
124124

125-
debug(f"Allocating host memory for {self.name}{self.shape_allocated} [{humanbytes(self.nbytes)}]")
125+
debug(f"Allocating host memory for {self.name}{self.shape_allocated} "
126+
f"[{humanbytes(self.nbytes)}]")
126127

127128
# Clear up both SymPy and Devito caches to drop unreachable data
128129
CacheManager.clear(force=False)
@@ -869,11 +870,11 @@ def _arg_check(self, args, intervals, **kwargs):
869870
data = args[self.name]
870871

871872
if len(data.shape) != self.ndim:
872-
raise InvalidArgument(f"Shape {data.shape} of runtime value `{self.name}` does not match "
873-
f"dimensions {self.dimensions}")
873+
raise InvalidArgument(f"Shape {data.shape} of runtime value `{self.name}` "
874+
f"does not match dimensions {self.dimensions}")
874875
if data.dtype != self.dtype:
875-
warning(f"Data type {data.dtype} of runtime value `{self.name}` does not match the "
876-
f"Function data type {self.dtype}")
876+
warning(f"Data type {data.dtype} of runtime value `{self.name}` "
877+
f"does not match the Function data type {self.dtype}")
877878

878879
# Check each Dimension for potential OOB accesses
879880
for i, s in zip(self.dimensions, data.shape):
@@ -883,8 +884,8 @@ def _arg_check(self, args, intervals, **kwargs):
883884
args.options['linearize'] and \
884885
self.is_regular and \
885886
data.size - 1 >= np.iinfo(np.int32).max:
886-
raise InvalidArgument(f"`{self.name}`, with its {data.size} elements, is too big for "
887-
"int32 pointer arithmetic. Consider using the "
887+
raise InvalidArgument(f"`{self.name}`, with its {data.size} elements, is too "
888+
"big for int32 pointer arithmetic. Consider using the "
888889
"'index-mode=int64' option, the save=Buffer(..) "
889890
"API (TimeFunction only), or domain "
890891
"decomposition via MPI")
@@ -1700,7 +1701,8 @@ def make(self, shape=None, initializer=None, allocator=None, **kwargs):
17001701
shape.append(int(v))
17011702
shape = tuple(shape)
17021703
elif len(shape) != self.ndim:
1703-
raise ValueError(f"`shape` must contain {self.ndim} integers, not {len(shape)}")
1704+
raise ValueError(f"`shape` must contain {self.ndim} integers, "
1705+
f"not {len(shape)}")
17041706
elif not all(is_integer(i) for i in shape):
17051707
raise ValueError(f"`shape` must contain integers (got `{str(shape)}`)")
17061708

devito/types/dimension.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,8 @@ def _arg_check(self, args, size, interval):
335335
if self.min_name not in args:
336336
raise InvalidArgument(f"No runtime value for {self.min_name}")
337337
if interval.is_Defined and args[self.min_name] + interval.lower < 0:
338-
raise InvalidArgument(f"OOB detected due to {self.min_name}={args[self.min_name]}")
338+
raise InvalidArgument(f"OOB detected due to "
339+
f"{self.min_name}={args[self.min_name]}")
339340

340341
if self.max_name not in args:
341342
raise InvalidArgument(f"No runtime value for {self.max_name}")
@@ -347,7 +348,8 @@ def _arg_check(self, args, size, interval):
347348
from devito.symbolics import normalize_args
348349
upper = interval.upper.subs(normalize_args(args))
349350
if args[self.max_name] + upper >= size:
350-
raise InvalidArgument(f"OOB detected due to {self.max_name}={args[self.max_name]}")
351+
raise InvalidArgument(f"OOB detected due to "
352+
f"{self.max_name}={args[self.max_name]}")
351353

352354
# Allow the specific case of max=min-1, which disables the loop
353355
if args[self.max_name] < args[self.min_name]-1:

0 commit comments

Comments
 (0)