Coverage for sources/accretive/exceptions.py: 100%
16 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-05 04:28 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-05 04:28 +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.
23 Provides a hierarchy of exceptions that are raised when accretive behavior
24 is violated. The hierarchy is designed to allow both specific and general
25 exception handling.
26'''
29from . import __ # pylint: disable=cyclic-import
32class Omniexception( __.ImmutableObject, BaseException ):
33 ''' Base for all exceptions raised by package API. '''
35 _attribute_visibility_includes_: __.cabc.Collection[ str ] = (
36 frozenset( ( '__cause__', '__context__', ) ) )
39class Omnierror( Omniexception, Exception ):
40 ''' Base for error exceptions raised by package API. '''
43class AttributeImmutabilityError( Omnierror, AttributeError, TypeError ):
44 ''' Attempt to reassign or delete immutable attribute. '''
46 def __init__( self, name: str ) -> None:
47 super( ).__init__( f"Cannot reassign or delete attribute {name!r}." )
50class DecoratorCompatibilityError( Omnierror, TypeError ):
51 ''' Attempt to apply decorator to incompatible class. '''
53 def __init__( self, class_name: str, method_name: str ) -> None:
54 super( ).__init__(
55 f"Cannot apply accretion decorator to {class_name!r} "
56 f"because it defines {method_name!r}.")
59class EntryImmutabilityError( Omnierror, TypeError ):
60 ''' Attempt to update or remove immutable dictionary entry. '''
62 def __init__( self, indicator: __.cabc.Hashable ) -> None:
63 super( ).__init__(
64 f"Cannot alter or remove existing entry for {indicator!r}." )
67class EntryValidityError( Omnierror, ValueError ):
68 ''' Attempt to add invalid entry to dictionary. '''
70 def __init__(
71 self, indicator: __.cabc.Hashable, value: __.typx.Any
72 ) -> None:
73 super( ).__init__(
74 f"Cannot add invalid entry with key, {indicator!r}, "
75 f"and value, {value!r}, to dictionary." )