From 9c76b31ba6399511cac1fa7388cdf31083bd7978 Mon Sep 17 00:00:00 2001 From: Fabio Luporini Date: Tue, 17 Dec 2024 13:58:54 +0000 Subject: [PATCH] misc: Convert into f-strings --- devito/operator/operator.py | 18 +++++++++--------- devito/passes/clusters/aliases.py | 4 ++-- devito/passes/clusters/buffering.py | 4 ++-- devito/types/dense.py | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/devito/operator/operator.py b/devito/operator/operator.py index dd65b44d23..b0666c6047 100644 --- a/devito/operator/operator.py +++ b/devito/operator/operator.py @@ -189,8 +189,8 @@ def _sanitize_exprs(cls, expressions, **kwargs): for i in expressions: if not isinstance(i, Evaluable): - raise CompilationError("`%s` is not an Evaluable object, " - "check again your Equation" % str(i)) + raise CompilationError(f"`{i!s}` is not an Evaluable object, " + "check again your Equation") return expressions @@ -554,7 +554,7 @@ def _prepare_arguments(self, autotune=None, **kwargs): if not configuration['ignore-unknowns']: for k, v in kwargs.items(): if k not in self._known_arguments: - raise InvalidArgument("Unrecognized argument %s=%s" % (k, v)) + raise InvalidArgument(f"Unrecognized argument `{k}={v}`") # Pre-process Dimension overrides. This may help ruling out ambiguities # when processing the `defaults` arguments. A topological sorting is used @@ -584,9 +584,9 @@ def _prepare_arguments(self, autotune=None, **kwargs): try: args.reduce_inplace() except ValueError: + v = [i for i in overrides if i.name in args] raise InvalidArgument( - "Override `%s` is incompatible with overrides `%s`" % - (p, [i for i in overrides if i.name in args]) + f"Override `{p}` is incompatible with overrides `{v}`" ) # Process data-carrier defaults @@ -608,9 +608,9 @@ def _prepare_arguments(self, autotune=None, **kwargs): pass elif is_integer(args[k]) and not contains_val(args[k], v): raise InvalidArgument( - "Default `%s` is incompatible with other args as `%s=%s`, " - "while `%s=%s` is expected. Perhaps you forgot to override " - "`%s`?" % (p, k, v, k, args[k], p) + f"Default `{p}` is incompatible with other args as " + f"`{k}={v}`, while `{k}={args[k]}` is expected. Perhaps " + f"you forgot to override `{p}`?" ) args = kwargs['args'] = args.reduce_all() @@ -742,7 +742,7 @@ def arguments(self, **kwargs): # Check all arguments are present for p in self.parameters: if args.get(p.name) is None: - raise InvalidArgument("No value found for parameter %s" % p.name) + raise InvalidArgument(f"No value found for parameter `{p.name}`") return args # Code generation and JIT compilation diff --git a/devito/passes/clusters/aliases.py b/devito/passes/clusters/aliases.py index e04b2bc67f..8f03246f30 100644 --- a/devito/passes/clusters/aliases.py +++ b/devito/passes/clusters/aliases.py @@ -374,8 +374,8 @@ def _select(self, variants): return variants[self.opt_schedule_strategy] except IndexError: raise CompilationError( - "Illegal schedule %d; generated %d schedules in total" - % (self.opt_schedule_strategy, len(variants)) + f"Illegal schedule {self.opt_schedule_strategy}; " + f"generated {len(variants)} schedules in total" ) return pick_best(variants) diff --git a/devito/passes/clusters/buffering.py b/devito/passes/clusters/buffering.py index 68d2c7d95e..88a07816f3 100644 --- a/devito/passes/clusters/buffering.py +++ b/devito/passes/clusters/buffering.py @@ -312,8 +312,8 @@ def generate_buffers(clusters, key, sregistry, options, **kwargs): dims = [d for d in f.dimensions if d not in bdims] if len(dims) != 1: - raise CompilationError("Unsupported multi-dimensional `buffering` " - "required by `%s`" % f) + raise CompilationError(f"Unsupported multi-dimensional `buffering` " + f"required by `{f}`") dim = dims.pop() if is_buffering(exprs): diff --git a/devito/types/dense.py b/devito/types/dense.py index 5ba24f48a1..b05beb656c 100644 --- a/devito/types/dense.py +++ b/devito/types/dense.py @@ -1375,8 +1375,8 @@ def __init_finalize__(self, *args, **kwargs): required_mem = np.dtype(self.dtype).itemsize * self.size if required_mem > available_mem: raise MemoryError( - "Trying to allocate more memory (%s) for `%s` than available (%s)" - % (humanbytes(required_mem), self.name, humanbytes(available_mem)) + f"Trying to allocate more memory ({humanbytes(required_mem)}) " + f"for `{self.name}` than available ({humanbytes(available_mem)})" ) if not isinstance(self.time_order, int): raise TypeError("`time_order` must be int")