Coverage for sources/frigid/exceptions.py: 100%
16 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-05 03:33 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-05 03: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.
23 Provides a hierarchy of exceptions that are raised when immutability is
24 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 modify immutable attribute. '''
46 def __init__( self, name: str ) -> None:
47 super( ).__init__(
48 f"Cannot assign or delete attribute {name!r}." )
51class DecoratorCompatibilityError( Omnierror, TypeError ):
52 ''' Attempt to apply decorator to incompatible class. '''
54 def __init__( self, class_name: str, method_name: str ) -> None:
55 # TODO: Use helper function to extract class name from class.
56 super( ).__init__(
57 f"Cannot apply immutability decorator to {class_name!r} "
58 f"because it defines {method_name!r}.")
61class EntryImmutabilityError( Omnierror, TypeError ):
62 ''' Attempt to modify immutable dictionary entry. '''
64 def __init__( self, key: __.cabc.Hashable ) -> None:
65 super( ).__init__(
66 f"Cannot add, alter, or remove entry for {key!r}." )
69class EntryValidityError( Omnierror, ValueError ):
70 ''' Attempt to add invalid entry to dictionary. '''
72 def __init__(
73 self, indicator: __.cabc.Hashable, value: __.typx.Any
74 ) -> None:
75 super( ).__init__(
76 f"Cannot add invalid entry with key, {indicator!r}, "
77 f"and value, {value!r}, to dictionary." )