From 20d1007f61e7ff72718153c4c3676ac470663b5e Mon Sep 17 00:00:00 2001 From: wolearyc Date: Tue, 13 Aug 2024 09:14:23 -0700 Subject: [PATCH] added UsageError --- ramannoodle/exceptions.py | 12 ++++++++++++ ramannoodle/polarizability/art.py | 15 +++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/ramannoodle/exceptions.py b/ramannoodle/exceptions.py index d02d5e1..6f7615a 100644 --- a/ramannoodle/exceptions.py +++ b/ramannoodle/exceptions.py @@ -40,6 +40,18 @@ def __init__(self, reason: str): pass +class UsageError(Exception): + """Raised when a user does something they shouldn't. + + This exception is used sparingly, as (ideally) the structure of the API should + dictate what the user should and shouldn't do. + + """ + + def __init__(self, reason: str): + pass + + def _shape_string(shape: Sequence[int | None]) -> str: """Get a string representing a shape. diff --git a/ramannoodle/polarizability/art.py b/ramannoodle/polarizability/art.py index 0ce314c..3083d02 100644 --- a/ramannoodle/polarizability/art.py +++ b/ramannoodle/polarizability/art.py @@ -15,6 +15,7 @@ get_shape_error, verify_ndarray_shape, InvalidDOFException, + UsageError, ) @@ -77,9 +78,13 @@ def add_dof( # pylint: disable=too-many-arguments ) -> None: """Disable add_dof. + Raises + ------ + UsageError + :meta private: """ - raise AttributeError("'ARTModel' object has no attribute 'add_dof'") + raise UsageError("add_dof should not be used; use add_art instead") def add_dof_from_files( self, @@ -89,9 +94,15 @@ def add_dof_from_files( ) -> None: """Disable add_dof_from_files. + Raises + ------ + UsageError + :meta private: """ - raise AttributeError("'ARTModel' object has no attribute 'add_dof_from_files'") + raise UsageError( + "add_dof_from_files should not be used; use add_art_from_files instead" + ) def add_art( self,