From 454c9053d4677f87f821f6764f1c0bc95e4a17f1 Mon Sep 17 00:00:00 2001 From: tkknight <2108488+tkknight@users.noreply.github.com> Date: Mon, 18 Dec 2023 10:09:09 +0000 Subject: [PATCH] fix for ruff rule D301 (#5646) * fixed for ruff rule D301. * additional fix * remove debug comment. --- .ruff.toml | 1 - benchmarks/benchmarks/cperf/equality.py | 4 ++-- benchmarks/benchmarks/sperf/equality.py | 2 +- lib/iris/_constraints.py | 2 +- lib/iris/_merge.py | 2 +- lib/iris/cube.py | 12 ++++++------ lib/iris/exceptions.py | 2 +- lib/iris/experimental/ugrid/load.py | 4 ++-- lib/iris/experimental/ugrid/mesh.py | 4 ++-- lib/iris/fileformats/_nc_load_rules/engine.py | 2 +- lib/iris/pandas.py | 4 ++-- lib/iris/tests/test_coding_standards.py | 4 ++-- .../tests/unit/coords/test__DimensionalMetadata.py | 2 +- 13 files changed, 22 insertions(+), 23 deletions(-) diff --git a/.ruff.toml b/.ruff.toml index e09d03c2d4..7ee7f985af 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -42,7 +42,6 @@ lint.ignore = [ "D211", # No blank lines allowed before class docstring "D214", # Section is over-indented "D300", # triple double quotes `""" / Use triple single quotes `'''` - "D301", # Use `r"""` if any backslashes in a docstring "D400", # First line should end with a period "D401", # First line of docstring should be in imperative mood: ... "D403", # First word of the first line should be capitalized diff --git a/benchmarks/benchmarks/cperf/equality.py b/benchmarks/benchmarks/cperf/equality.py index 9a3ceded9f..a25cf99128 100644 --- a/benchmarks/benchmarks/cperf/equality.py +++ b/benchmarks/benchmarks/cperf/equality.py @@ -9,7 +9,7 @@ class EqualityMixin(SingleDiagnosticMixin): - """Uses :class:`SingleDiagnosticMixin` as the realistic case will be comparing + r"""Uses :class:`SingleDiagnosticMixin` as the realistic case will be comparing :class:`~iris.cube.Cube`\\ s that have been loaded from file. """ @@ -24,7 +24,7 @@ def setup(self, file_type, three_d=False, three_times=False): @on_demand_benchmark class CubeEquality(EqualityMixin): - """Benchmark time and memory costs of comparing LFRic and UM + r"""Benchmark time and memory costs of comparing LFRic and UM :class:`~iris.cube.Cube`\\ s. """ diff --git a/benchmarks/benchmarks/sperf/equality.py b/benchmarks/benchmarks/sperf/equality.py index 827490b082..813cfad6bf 100644 --- a/benchmarks/benchmarks/sperf/equality.py +++ b/benchmarks/benchmarks/sperf/equality.py @@ -10,7 +10,7 @@ @on_demand_benchmark class CubeEquality(FileMixin): - """Benchmark time and memory costs of comparing :class:`~iris.cube.Cube`\\ s + r"""Benchmark time and memory costs of comparing :class:`~iris.cube.Cube`\\ s with attached :class:`~iris.experimental.ugrid.mesh.Mesh`\\ es. Uses :class:`FileMixin` as the realistic case will be comparing diff --git a/lib/iris/_constraints.py b/lib/iris/_constraints.py index 4ce14d5ece..1d81cd603b 100644 --- a/lib/iris/_constraints.py +++ b/lib/iris/_constraints.py @@ -33,7 +33,7 @@ def __init__(self, name=None, cube_func=None, coord_values=None, **kwargs): ---------- name : str or None, optional If a string, it is used as the name to match against the - :attr:`iris.cube.Cube.names` property. TREMTEST + :attr:`iris.cube.Cube.names` property. cube_func : callable or None, optional If a callable, it must accept a Cube as its first and only argument and return either True or False. diff --git a/lib/iris/_merge.py b/lib/iris/_merge.py index db2b410b94..19848ff244 100644 --- a/lib/iris/_merge.py +++ b/lib/iris/_merge.py @@ -525,7 +525,7 @@ def _is_combination(name): def build_indexes(positions): - """Construct a mapping for each candidate dimension that maps for each + r"""Construct a mapping for each candidate dimension that maps for each of its scalar values the set of values for each of the other candidate dimensions. diff --git a/lib/iris/cube.py b/lib/iris/cube.py index 7e35893533..aff9ad5d0d 100644 --- a/lib/iris/cube.py +++ b/lib/iris/cube.py @@ -752,7 +752,7 @@ def _is_single_item(testee): class CubeAttrsDict(MutableMapping): - """A :class:`dict`\\-like object for :attr:`iris.cube.Cube.attributes`, + r"""A :class:`dict`\\-like object for :attr:`iris.cube.Cube.attributes`, providing unified user access to combined cube "local" and "global" attributes dictionaries, with the access behaviour of an ordinary (single) dictionary. @@ -2018,7 +2018,7 @@ def coords( dim_coords=None, mesh_coords=None, ): - """Return a list of coordinates from the :class:`Cube` that match the + r"""Return a list of coordinates from the :class:`Cube` that match the provided criteria. .. seealso:: @@ -2184,7 +2184,7 @@ def coord( dim_coords=None, mesh_coords=None, ): - """Return a single coordinate from the :class:`Cube` that matches the + r"""Return a single coordinate from the :class:`Cube` that matches the provided criteria. .. note:: @@ -2359,7 +2359,7 @@ def _any_meshcoord(self): @property def mesh(self): - """Return the unstructured :class:`~iris.experimental.ugrid.Mesh` + r"""Return the unstructured :class:`~iris.experimental.ugrid.Mesh` associated with the cube, if the cube has any :class:`~iris.experimental.ugrid.MeshCoord`\\ s, or ``None`` if it has none. @@ -2379,7 +2379,7 @@ def mesh(self): @property def location(self): - """Return the mesh "location" of the cube data, if the cube has any + r"""Return the mesh "location" of the cube data, if the cube has any :class:`~iris.experimental.ugrid.MeshCoord`\\ s, or ``None`` if it has none. @@ -2398,7 +2398,7 @@ def location(self): return result def mesh_dim(self): - """Return the cube dimension of the mesh, if the cube has any + r"""Return the cube dimension of the mesh, if the cube has any :class:`~iris.experimental.ugrid.MeshCoord`\\ s, or ``None`` if it has none. diff --git a/lib/iris/exceptions.py b/lib/iris/exceptions.py index 8fad591658..36523b8ed6 100644 --- a/lib/iris/exceptions.py +++ b/lib/iris/exceptions.py @@ -176,7 +176,7 @@ class CannotAddError(ValueError): class IrisUserWarning(UserWarning): - """Base class for :class:`UserWarning`\\ s generated by Iris.""" + r"""Base class for :class:`UserWarning`\\ s generated by Iris.""" pass diff --git a/lib/iris/experimental/ugrid/load.py b/lib/iris/experimental/ugrid/load.py index 317d64ca04..07cc20a65a 100644 --- a/lib/iris/experimental/ugrid/load.py +++ b/lib/iris/experimental/ugrid/load.py @@ -3,7 +3,7 @@ # This file is part of Iris and is released under the BSD license. # See LICENSE in the root of the repository for full licensing details. -"""Extensions to Iris' NetCDF loading to allow the construction of +r"""Extensions to Iris' NetCDF loading to allow the construction of :class:`~iris.experimental.ugrid.mesh.Mesh`\\ es from UGRID data in the file. Eventual destination: :mod:`iris.fileformats.netcdf`. @@ -143,7 +143,7 @@ def load_mesh(uris, var_name=None): def load_meshes(uris, var_name=None): - """Load :class:`~iris.experimental.ugrid.mesh.Mesh` objects from one or more NetCDF files. + r"""Load :class:`~iris.experimental.ugrid.mesh.Mesh` objects from one or more NetCDF files. Parameters ---------- diff --git a/lib/iris/experimental/ugrid/mesh.py b/lib/iris/experimental/ugrid/mesh.py index 02b26f41f1..5d320384b7 100644 --- a/lib/iris/experimental/ugrid/mesh.py +++ b/lib/iris/experimental/ugrid/mesh.py @@ -659,7 +659,7 @@ def normalise(element, axis): @classmethod def from_coords(cls, *coords): - """Construct a :class:`Mesh` by derivation from one or more + r"""Construct a :class:`Mesh` by derivation from one or more :class:`~iris.coords.Coord`\\ s. The :attr:`~Mesh.topology_dimension`, :class:`~iris.coords.Coord` @@ -1865,7 +1865,7 @@ def to_MeshCoord(self, location, axis): return MeshCoord(mesh=self, location=location, axis=axis) def to_MeshCoords(self, location): - """Generate a tuple of + r"""Generate a tuple of :class:`~iris.experimental.ugrid.mesh.MeshCoord`\\ s, each referencing the current :class:`Mesh`, one for each :attr:`AXES` value, passing through the ``location`` argument. diff --git a/lib/iris/fileformats/_nc_load_rules/engine.py b/lib/iris/fileformats/_nc_load_rules/engine.py index 20527fdee4..e43a1c5c4b 100644 --- a/lib/iris/fileformats/_nc_load_rules/engine.py +++ b/lib/iris/fileformats/_nc_load_rules/engine.py @@ -20,7 +20,7 @@ class FactEntity: - """An object with an 'entity_lists' property which is a dict of 'FactList's. + r"""An object with an 'entity_lists' property which is a dict of 'FactList's. A Factlist, in turn, is an object with property 'case_specific_facts', which is a list of tuples of strings diff --git a/lib/iris/pandas.py b/lib/iris/pandas.py index c5b4b0b498..fa12f087e4 100644 --- a/lib/iris/pandas.py +++ b/lib/iris/pandas.py @@ -192,7 +192,7 @@ def as_cubes( cell_measure_cols=None, ancillary_variable_cols=None, ): - """Convert a Pandas Series/DataFrame into n-dimensional Iris Cubes, including dimensional metadata. + r"""Convert a Pandas Series/DataFrame into n-dimensional Iris Cubes, including dimensional metadata. The index of `pandas_structure` will be used for generating the :class:`~iris.cube.Cube` dimension(s) and :class:`~iris.coords.DimCoord`\\ s. @@ -617,7 +617,7 @@ def as_data_frame( add_cell_measures=False, add_ancillary_variables=False, ): - """Convert a :class:`~iris.cube.Cube` to a :class:`pandas.DataFrame`. + r"""Convert a :class:`~iris.cube.Cube` to a :class:`pandas.DataFrame`. :attr:`~iris.cube.Cube.dim_coords` and :attr:`~iris.cube.Cube.data` are flattened into a long-style :class:`~pandas.DataFrame`. Other diff --git a/lib/iris/tests/test_coding_standards.py b/lib/iris/tests/test_coding_standards.py index 7be3acca63..423d6bd092 100644 --- a/lib/iris/tests/test_coding_standards.py +++ b/lib/iris/tests/test_coding_standards.py @@ -125,7 +125,7 @@ def test_python_versions(): def test_categorised_warnings(): - """To ensure that all UserWarnings raised by Iris are categorised, for ease of use. + r"""To ensure that all UserWarnings raised by Iris are categorised, for ease of use. No obvious category? Use the parent: :class:`iris.exceptions.IrisUserWarning`. @@ -182,7 +182,7 @@ class _WarnComboCfDefaulting(IrisCfWarning, IrisDefaultingWarning): class TestLicenseHeaders(tests.IrisTest): @staticmethod def whatchanged_parse(whatchanged_output): - """Returns a generator of tuples of data parsed from + r"""Returns a generator of tuples of data parsed from "git whatchanged --pretty='TIME:%at". The tuples are of the form ``(filename, last_commit_datetime)`` diff --git a/lib/iris/tests/unit/coords/test__DimensionalMetadata.py b/lib/iris/tests/unit/coords/test__DimensionalMetadata.py index cf850ce907..caff08fb66 100644 --- a/lib/iris/tests/unit/coords/test__DimensionalMetadata.py +++ b/lib/iris/tests/unit/coords/test__DimensionalMetadata.py @@ -172,7 +172,7 @@ def coord_representations(self, *args, **kwargs): return self.repr_str_strings(coord) def assertLines(self, list_of_expected_lines, string_result): - """Assert equality between a result and expected output lines. + r"""Assert equality between a result and expected output lines. For convenience, the 'expected lines' are joined with a '\\n', because a list of strings is nicer to construct in code.