Skip to content

Commit

Permalink
ci(lint): enforce rule RUF012
Browse files Browse the repository at this point in the history
  • Loading branch information
ljgray committed May 1, 2024
1 parent bea4d36 commit bb953f9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 27 deletions.
10 changes: 3 additions & 7 deletions caput/memh5.py
Original file line number Diff line number Diff line change
Expand Up @@ -1271,11 +1271,7 @@ def __iter__(self):
return self._data.__iter__()

def __repr__(self):
return '<memh5 common dataset {}: shape {}, type "{}">'.format(
repr(self._name),
repr(self.shape),
repr(self.dtype),
)
return f'<memh5 common dataset {self._name!r}: shape {self.shape!r}, type "{self.dtype!r}">'

def __eq__(self, other):
if not isinstance(other, MemDatasetCommon):
Expand Down Expand Up @@ -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
Expand Down
26 changes: 7 additions & 19 deletions caput/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -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):
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bb953f9

Please sign in to comment.