Coverage for sources/accretive/exceptions.py: 100%
22 statements
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-20 01:33 +0000
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-20 01:33 +0000
1# vim: set filetype=python fileencoding=utf-8:
2# -*- coding: utf-8 -*-
4#============================================================================#
5# #
6# Licensed under the Apache License, Version 2.0 (the "License"); #
7# you may not use this file except in compliance with the License. #
8# You may obtain a copy of the License at #
9# #
10# http://www.apache.org/licenses/LICENSE-2.0 #
11# #
12# Unless required by applicable law or agreed to in writing, software #
13# distributed under the License is distributed on an "AS IS" BASIS, #
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
15# See the License for the specific language governing permissions and #
16# limitations under the License. #
17# #
18#============================================================================#
21''' Family of exceptions for package API.
23Provides a hierarchy of exceptions that are raised when accretive behavior is
24violated. The hierarchy is designed to allow both specific and general
25exception handling.
27* ``Omniexception``: Base for all package exceptions
28* ``Omnierror``: Base for all package errors
30* ``AttributeImmutabilityError``: Raised for attribute modification
31* ``EntryImmutabilityError``: Raised for dictionary entry modification
32* ``EntryValidityError``: Raised for invalid dictionary entries
33* ``OperationValidityError``: Raised for invalid operations
35.. note::
37 Some exception names from earlier versions are maintained as aliases for
38 backward compatibility but are deprecated.
39'''
42from . import __ # pylint: disable=cyclic-import
45class Omniexception( __.InternalObject, BaseException ):
46 ''' Base for all exceptions raised by package API. '''
48 _attribute_visibility_includes_: __.cabc.Collection[ str ] = (
49 frozenset( ( '__cause__', '__context__', ) ) )
52class Omnierror( Omniexception, Exception ):
53 ''' Base for error exceptions raised by package API. '''
56class AttributeImmutabilityError( Omnierror, AttributeError, TypeError ):
57 ''' Attempt to reassign or delete immutable attribute. '''
59 def __init__( self, name: str ) -> None:
60 super( ).__init__( f"Cannot reassign or delete attribute {name!r}." )
63class EntryImmutabilityError( Omnierror, TypeError ):
64 ''' Attempt to update or remove immutable dictionary entry. '''
66 def __init__( self, indicator: __.cabc.Hashable ) -> None:
67 super( ).__init__(
68 f"Cannot alter or remove existing entry for {indicator!r}." )
71class EntryValidityError( Omnierror, ValueError ):
72 ''' Attempt to add invalid entry to dictionary. '''
74 def __init__( self, indicator: __.cabc.Hashable, value: __.a.Any ) -> None:
75 super( ).__init__(
76 f"Cannot add invalid entry with key, {indicator!r}, "
77 f"and value, {value!r}, to dictionary." )
80class OperationValidityError( Omnierror, RuntimeError, TypeError ):
81 ''' Attempt to perform invalid operation. '''
83 def __init__( self, name: str ) -> None:
84 super( ).__init__( f"Operation {name!r} is not valid on this object." )
87## BEGIN: Deprecated Exceptions
88# TODO: release 3.0: Remove.
91class EntryValidationError( EntryValidityError ):
92 ''' Attempt to add invalid entry to dictionary.
94 .. deprecated:: 2.1
95 Please use :py:exc:`EntryValidityError` instead.
96 '''
99class IndelibleAttributeError( AttributeImmutabilityError ):
100 ''' Attempt to reassign or delete indelible attribute.
102 .. deprecated:: 2.1
103 Please use :py:exc:`AttributeImmutabilityError` instead.
104 '''
107class IndelibleEntryError( EntryImmutabilityError ):
108 ''' Attempt to update or remove indelible dictionary entry.
110 .. deprecated:: 2.1
111 Please use :py:exc:`EntryImmutabilityError` instead.
112 '''
114 def __init__( self, indicator: __.a.Any ) -> None:
115 super( ).__init__( indicator )
118class InvalidOperationError( OperationValidityError ):
119 ''' Attempt to perform invalid operation.
121 .. deprecated:: 2.1
122 Please use :py:exc:`OperationValidityError` instead.
123 '''