From 3b170954ca734b5ebb314cfb6df989d4b311f87d Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauldmccarthy@gmail.com> Date: Sat, 14 Jan 2023 06:46:49 +0000 Subject: [PATCH] MNT: Use custom error type (sub-classed from ValueError, so not an API change) --- fsl/data/mesh.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/fsl/data/mesh.py b/fsl/data/mesh.py index 54c3b87ae..9fc62f14f 100644 --- a/fsl/data/mesh.py +++ b/fsl/data/mesh.py @@ -41,6 +41,13 @@ import fsl.transform.affine as affine log = logging.getLogger(__name__) +class IncompatibleVerticesError(ValueError): + """``ValueError`` raised by the :meth:`Mesh.addVertices` method if + an attempt is made to add a vertex set with the wrong number of + vertices. + """ + + class Mesh(notifier.Notifier, meta.Meta): """The ``Mesh`` class represents a 3D model. A mesh is defined by a collection of ``N`` vertices, and ``M`` triangles. The triangles are @@ -412,8 +419,8 @@ class Mesh(notifier.Notifier, meta.Meta): :returns: The vertices, possibly reshaped - :raises: ``ValueError`` if the provided ``vertices`` array - has the wrong number of vertices. + :raises: ``IncompatibleVerticesError`` if the provided + ``vertices`` array has the wrong number of vertices. """ if self.__indices is None: @@ -434,10 +441,9 @@ class Mesh(notifier.Notifier, meta.Meta): # reshape raised an error - # wrong number of vertices except ValueError: - raise ValueError('{}: invalid number of vertices: ' - '{} != ({}, 3)'.format(key, - vertices.shape, - self.nvertices)) + raise IncompatibleVerticesError( + f'{key}: invalid number of vertices: ' + f'{vertices.shape} != ({self.nvertices}, 3)') self.__vertices[key] = vertices self.__vindices[key] = self.__indices -- GitLab