From bb953f9abb96b111dbea0fa0a31ce6a306112633 Mon Sep 17 00:00:00 2001 From: Liam Gray Date: Tue, 16 Jan 2024 16:47:52 -0800 Subject: [PATCH] ci(lint): enforce rule RUF012 --- caput/memh5.py | 10 +++------- caput/pipeline.py | 26 +++++++------------------- pyproject.toml | 1 - 3 files changed, 10 insertions(+), 27 deletions(-) diff --git a/caput/memh5.py b/caput/memh5.py index c4e7e491..a400988d 100644 --- a/caput/memh5.py +++ b/caput/memh5.py @@ -1271,11 +1271,7 @@ def __iter__(self): return self._data.__iter__() def __repr__(self): - return ''.format( - repr(self._name), - repr(self.shape), - repr(self.dtype), - ) + return f'' def __eq__(self, other): if not isinstance(other, MemDatasetCommon): @@ -2172,9 +2168,9 @@ def history(self): out = {} for name, value in self._data["history"].items(): warnings.warn( - "memh5 dataset {} is using a deprecated history format. Read support of " + f"memh5 dataset {self.name} is using a deprecated history format. Read support of " "files using this format will be continued for now, but you should " - "update the instance of caput that wrote this file.".format(self.name), + "update the instance of caput that wrote this file.", DeprecationWarning, ) out[name] = value.attrs diff --git a/caput/pipeline.py b/caput/pipeline.py index 0ca205d1..c3c2518c 100644 --- a/caput/pipeline.py +++ b/caput/pipeline.py @@ -434,17 +434,13 @@ def _get_versions(modules): modules = [modules] if not isinstance(modules, list): raise config.CaputConfigError( - "Value of 'save_versions' is of type '{}' (expected 'str' or 'list(str)').".format( - type(modules).__name__ - ) + f"Value of 'save_versions' is of type '{type(modules).__name__}' (expected 'str' or 'list(str)')." ) versions = {} for module in modules: if not isinstance(module, str): raise config.CaputConfigError( - "Found value of type '{}' in list 'save_versions' (expected 'str').".format( - type(module).__name__ - ) + f"Found value of type '{type(module).__name__}' in list 'save_versions' (expected 'str')." ) try: versions[module] = importlib.import_module(module).__version__ @@ -721,10 +717,8 @@ def _validate_task(task, in_, requires, all_out_values): for v in value: if v not in all_out_values: raise config.CaputConfigError( - "Value '{}' for task {} has no corresponding 'out' from another task " - "(Value {} is not in {}).".format( - key, type(task), v, all_out_values - ) + f"Value '{key}' for task {type(task)} has no corresponding 'out' from another task " + f"(Value {v} is not in {all_out_values})." ) def _setup_task(self, task_spec): @@ -750,11 +744,7 @@ def _setup_task(self, task_spec): try: task_cls = misc.import_class(task_path) except (config.CaputConfigError, AttributeError, ModuleNotFoundError) as e: - msg = "Loading task '{}' caused error {}:\n\t{}".format( - task_path, - e.__class__.__name__, - str(e), - ) + msg = f"Loading task '{task_path}' caused error {e.__class__.__name__}:\n\t{e!s}" raise config.CaputConfigError(msg) from e # Get the parameters and initialize the class. @@ -817,10 +807,8 @@ def add_task(self, task, requires=None, in_=None, out=None): """ try: task._setup_keys(requires=requires, in_=in_, out=out) - except Exception as e: # noqa: BLE001 - msg = "Setting up keys for task {} caused an error:\n\t{}".format( - task.__class__.__name__, str(e) - ) + except Exception as e: + msg = f"Setting up keys for task {task.__class__.__name__} caused an error:\n\t{e!s}" raise config.CaputConfigError(msg) from e # The tasks own custom validation method diff --git a/pyproject.toml b/pyproject.toml index e4b312dc..bf985a09 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,7 +35,6 @@ lint.ignore = [ "D413", # D413: Missing blank line after last section "D416", # D416: Section name should end with a colon "NPY002", # NPY002: replace legacy numpy.random calls with np.random.Generator - "RUF012", # RUF012 Mutable class attributes should be annotated with `typing.ClassVar` ] # Ignore the following directories