accretive 1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- accretive/__.py +187 -0
- accretive/__init__.py +70 -0
- accretive/_annotations.py +90 -0
- accretive/_docstrings.py +136 -0
- accretive/aaliases.py +41 -0
- accretive/classes.py +88 -0
- accretive/complete/__init__.py +49 -0
- accretive/complete/aaliases.py +41 -0
- accretive/complete/classes.py +52 -0
- accretive/complete/dictionaries.py +53 -0
- accretive/complete/modules.py +45 -0
- accretive/complete/namespaces.py +41 -0
- accretive/complete/objects.py +41 -0
- accretive/complete/qaliases.py +44 -0
- accretive/concealment/__init__.py +48 -0
- accretive/concealment/aaliases.py +41 -0
- accretive/concealment/classes.py +42 -0
- accretive/concealment/dictionaries.py +46 -0
- accretive/concealment/modules.py +39 -0
- accretive/concealment/namespaces.py +35 -0
- accretive/concealment/objects.py +35 -0
- accretive/concealment/qaliases.py +44 -0
- accretive/dictionaries.py +182 -0
- accretive/exceptions.py +66 -0
- accretive/modules.py +48 -0
- accretive/namespaces.py +65 -0
- accretive/objects.py +61 -0
- accretive/protection/__init__.py +48 -0
- accretive/protection/aaliases.py +41 -0
- accretive/protection/classes.py +46 -0
- accretive/protection/dictionaries.py +47 -0
- accretive/protection/modules.py +42 -0
- accretive/protection/namespaces.py +38 -0
- accretive/protection/objects.py +38 -0
- accretive/protection/qaliases.py +44 -0
- accretive/qaliases.py +44 -0
- accretive-1.0.dist-info/METADATA +235 -0
- accretive-1.0.dist-info/RECORD +40 -0
- accretive-1.0.dist-info/WHEEL +4 -0
- accretive-1.0.dist-info/licenses/LICENSE.txt +202 -0
accretive/__.py
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# vim: set filetype=python fileencoding=utf-8:
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
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
|
+
#============================================================================#
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
''' Common constants, imports, and utilities. '''
|
|
22
|
+
|
|
23
|
+
# ruff: noqa: F401
|
|
24
|
+
# pylint: disable=unused-import
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
from abc import ABCMeta as ABCFactory
|
|
28
|
+
from collections.abc import Mapping as AbstractDictionary
|
|
29
|
+
from functools import partial as partial_function
|
|
30
|
+
from inspect import cleandoc as clean_docstring
|
|
31
|
+
from sys import modules
|
|
32
|
+
from types import (
|
|
33
|
+
MappingProxyType as DictionaryProxy,
|
|
34
|
+
ModuleType as Module,
|
|
35
|
+
SimpleNamespace,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
from . import _annotations as _a
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
_no_value = object( )
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class ClassConcealerExtension( type ):
|
|
45
|
+
''' Conceals class attributes according to some criteria.
|
|
46
|
+
|
|
47
|
+
By default, public attributes are displayed.
|
|
48
|
+
'''
|
|
49
|
+
|
|
50
|
+
_class_attribute_visibility_includes_: _a.Collection[ str ] = frozenset( )
|
|
51
|
+
|
|
52
|
+
def __dir__( class_ ) -> _a.Tuple[ str, ... ]:
|
|
53
|
+
return tuple( sorted(
|
|
54
|
+
name for name in super( ).__dir__( )
|
|
55
|
+
if not name.startswith( '_' )
|
|
56
|
+
or name in class_._class_attribute_visibility_includes_ ) )
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class ConcealerExtension:
|
|
60
|
+
''' Conceals instance attributes according to some criteria.
|
|
61
|
+
|
|
62
|
+
By default, public attributes are displayed.
|
|
63
|
+
'''
|
|
64
|
+
|
|
65
|
+
_attribute_visibility_includes_: _a.Collection[ str ] = frozenset( )
|
|
66
|
+
|
|
67
|
+
def __dir__( self ) -> _a.Tuple[ str, ... ]:
|
|
68
|
+
return tuple( sorted(
|
|
69
|
+
name for name in super( ).__dir__( )
|
|
70
|
+
if not name.startswith( '_' )
|
|
71
|
+
or name in self._attribute_visibility_includes_ ) )
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class CoreDictionary( ConcealerExtension, dict ): # type: ignore[type-arg]
|
|
75
|
+
''' Accretive subclass of :py:class:`dict`.
|
|
76
|
+
|
|
77
|
+
Can be used as an instance dictionary.
|
|
78
|
+
|
|
79
|
+
Prevents attempts to mutate dictionary via inherited interface.
|
|
80
|
+
'''
|
|
81
|
+
|
|
82
|
+
def __init__(
|
|
83
|
+
self,
|
|
84
|
+
*iterables: _a.DictionaryPositionalArgument,
|
|
85
|
+
**entries: _a.DictionaryNominativeArgument
|
|
86
|
+
):
|
|
87
|
+
super( ).__init__( )
|
|
88
|
+
self.update( *iterables, **entries )
|
|
89
|
+
|
|
90
|
+
def __delitem__( self, key: _a.Hashable ) -> None:
|
|
91
|
+
from .exceptions import IndelibleEntryError
|
|
92
|
+
raise IndelibleEntryError( key )
|
|
93
|
+
|
|
94
|
+
def __setitem__( self, key: _a.Hashable, value: _a.Any ) -> None:
|
|
95
|
+
from .exceptions import IndelibleEntryError
|
|
96
|
+
if key in self: raise IndelibleEntryError( key )
|
|
97
|
+
super( ).__setitem__( key, value )
|
|
98
|
+
|
|
99
|
+
def clear( self ) -> _a.Never:
|
|
100
|
+
''' Raises exception. Cannot clear indelible entries. '''
|
|
101
|
+
from .exceptions import InvalidOperationError
|
|
102
|
+
raise InvalidOperationError( 'clear' )
|
|
103
|
+
|
|
104
|
+
def copy( self ) -> _a.Self:
|
|
105
|
+
''' Provides fresh copy of dictionary. '''
|
|
106
|
+
return type( self )( self )
|
|
107
|
+
|
|
108
|
+
def pop( # pylint: disable=unused-argument
|
|
109
|
+
self, key: _a.Hashable, default: _a.Any = _no_value
|
|
110
|
+
) -> _a.Never:
|
|
111
|
+
''' Raises exception. Cannot pop indelible entry. '''
|
|
112
|
+
from .exceptions import InvalidOperationError
|
|
113
|
+
raise InvalidOperationError( 'pop' )
|
|
114
|
+
|
|
115
|
+
def popitem( self ) -> _a.Never:
|
|
116
|
+
''' Raises exception. Cannot pop indelible entry. '''
|
|
117
|
+
from .exceptions import InvalidOperationError
|
|
118
|
+
raise InvalidOperationError( 'popitem' )
|
|
119
|
+
|
|
120
|
+
def update( # type: ignore[override]
|
|
121
|
+
self,
|
|
122
|
+
*iterables: _a.DictionaryPositionalArgument,
|
|
123
|
+
**entries: _a.DictionaryNominativeArgument
|
|
124
|
+
) -> _a.Self:
|
|
125
|
+
''' Adds new entries as a batch. '''
|
|
126
|
+
from itertools import chain
|
|
127
|
+
# Add values in order received, enforcing no alteration.
|
|
128
|
+
for indicator, value in chain.from_iterable( map(
|
|
129
|
+
lambda element: (
|
|
130
|
+
element.items( )
|
|
131
|
+
if isinstance( element, AbstractDictionary )
|
|
132
|
+
else element
|
|
133
|
+
),
|
|
134
|
+
( *iterables, entries )
|
|
135
|
+
) ): self[ indicator ] = value
|
|
136
|
+
return self
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
class Docstring( str ):
|
|
140
|
+
''' Dedicated docstring container. '''
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def discover_fqname( obj: _a.Any ) -> str:
|
|
144
|
+
''' Discovers fully-qualified name for class of instance. '''
|
|
145
|
+
class_ = type( obj )
|
|
146
|
+
return f"{class_.__module__}.{class_.__qualname__}"
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def discover_public_attributes(
|
|
150
|
+
attributes: _a.Mapping[ str, _a.Any ]
|
|
151
|
+
) -> _a.Tuple[ str, ... ]:
|
|
152
|
+
''' Discovers public attributes of certain types from dictionary.
|
|
153
|
+
|
|
154
|
+
By default, callables, including classes, are discovered.
|
|
155
|
+
'''
|
|
156
|
+
return tuple( sorted(
|
|
157
|
+
name for name, attribute in attributes.items( )
|
|
158
|
+
if not name.startswith( '_' ) and callable( attribute ) ) )
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def generate_docstring(
|
|
162
|
+
*fragment_ids: _a.Union[ _a.Type, Docstring, str ]
|
|
163
|
+
) -> str:
|
|
164
|
+
''' Sews together docstring fragments into clean docstring. '''
|
|
165
|
+
from inspect import cleandoc, getdoc, isclass
|
|
166
|
+
from ._docstrings import TABLE
|
|
167
|
+
fragments = [ ]
|
|
168
|
+
for fragment_id in fragment_ids:
|
|
169
|
+
if isclass( fragment_id ): fragment = getdoc( fragment_id ) or ''
|
|
170
|
+
elif isinstance( fragment_id, Docstring ): fragment = fragment_id
|
|
171
|
+
else: fragment = TABLE[ fragment_id ]
|
|
172
|
+
fragments.append( cleandoc( fragment ) )
|
|
173
|
+
return '\n\n'.join( fragments )
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def reclassify_modules(
|
|
177
|
+
attributes: _a.Mapping[ str, _a.Any ],
|
|
178
|
+
to_class: _a.Type[ Module ]
|
|
179
|
+
) -> None:
|
|
180
|
+
''' Reclassifies modules in dictionary with custom module type. '''
|
|
181
|
+
for attribute in attributes.values( ):
|
|
182
|
+
if not isinstance( attribute, Module ): continue
|
|
183
|
+
if isinstance( attribute, to_class ): continue
|
|
184
|
+
attribute.__class__ = to_class
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
__all__ = ( )
|
accretive/__init__.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# vim: set filetype=python fileencoding=utf-8:
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
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
|
+
#============================================================================#
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
''' Accretive data structures. '''
|
|
22
|
+
|
|
23
|
+
# ruff: noqa: F401,F403
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
from . import __
|
|
27
|
+
from . import aaliases
|
|
28
|
+
from . import classes
|
|
29
|
+
from . import complete
|
|
30
|
+
from . import concealment
|
|
31
|
+
from . import dictionaries
|
|
32
|
+
from . import exceptions
|
|
33
|
+
from . import modules
|
|
34
|
+
from . import namespaces
|
|
35
|
+
from . import objects
|
|
36
|
+
from . import protection
|
|
37
|
+
from . import qaliases
|
|
38
|
+
|
|
39
|
+
from .classes import *
|
|
40
|
+
from .dictionaries import *
|
|
41
|
+
from .modules import *
|
|
42
|
+
from .namespaces import *
|
|
43
|
+
from .objects import *
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
_subpackages = ( concealment, protection, complete )
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
__doc__ = __.generate_docstring(
|
|
50
|
+
__.Docstring( __doc__ ),
|
|
51
|
+
'subpackage behavior: attributes accretion',
|
|
52
|
+
__.Docstring(
|
|
53
|
+
'Subpackages with variants of the data structures are available:' ),
|
|
54
|
+
__.Docstring( '\n\n'.join(
|
|
55
|
+
"* :py:mod:`{name}`: {headline}".format(
|
|
56
|
+
name = package.__package__,
|
|
57
|
+
headline = (
|
|
58
|
+
package.__doc__ or '' ).split( '\n', maxsplit = 1 )[ 0 ] )
|
|
59
|
+
for package in _subpackages ) ) )
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
__all__ = __.discover_public_attributes( globals( ) )
|
|
63
|
+
__version__ = '1.0'
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
complete.modules.reclassify_modules( globals( ) )
|
|
67
|
+
for _subpackage in _subpackages:
|
|
68
|
+
complete.modules.reclassify_modules( vars( _subpackage ) )
|
|
69
|
+
_attribute_visibility_includes_ = frozenset( ( '__version__', ) )
|
|
70
|
+
__.modules[ __package__ ].__class__ = complete.modules.Module
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# vim: set filetype=python fileencoding=utf-8:
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
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
|
+
#============================================================================#
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
''' Standard annotations across Python versions. '''
|
|
22
|
+
|
|
23
|
+
# ruff: noqa: F401
|
|
24
|
+
# pylint: disable=unused-import
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
from types import ModuleType as Module
|
|
28
|
+
|
|
29
|
+
from typing_extensions import (
|
|
30
|
+
Annotated as Annotation,
|
|
31
|
+
Any,
|
|
32
|
+
Callable,
|
|
33
|
+
Collection, # TODO: Python 3.9: collections.abc.Collection
|
|
34
|
+
Dict, # TODO: Python 3.9: dict
|
|
35
|
+
Doc,
|
|
36
|
+
Hashable, # TODO: Python 3.9: collections.abc.Hashable
|
|
37
|
+
ItemsView, # TODO: Python 3.9: collections.abc.ItemsView
|
|
38
|
+
Iterable, # TODO: Python 3.9: collections.abc.Iterable
|
|
39
|
+
Iterator, # TODO: Python 3.9: collections.abc.Iterator
|
|
40
|
+
KeysView, # TODO: Python 3.9: collections.abc.KeysView
|
|
41
|
+
Mapping, # TODO: Python 3.9: collections.abc.Mapping
|
|
42
|
+
MutableMapping, # TODO: Python 3.9: collections.abc.MutableMapping
|
|
43
|
+
Never,
|
|
44
|
+
Self,
|
|
45
|
+
Tuple, # TODO: Python 3.9: collections.abc.Sequence
|
|
46
|
+
Type, # TODO: Python 3.9: type
|
|
47
|
+
TypeAlias,
|
|
48
|
+
Union, # TODO: Python 3.10: bitwise-OR operator ('|')
|
|
49
|
+
ValuesView, # TODO: Python 3.9: collections.abc.ValuesView
|
|
50
|
+
cast,
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
# TODO? Python 3.10: Import 'NotImplementedType' from 'types'.
|
|
55
|
+
# Note: According to https://stackoverflow.com/a/75185542/14833542,
|
|
56
|
+
# Mypy implicitly considers 'NotImplemented' as a result of the dunder
|
|
57
|
+
# methods for comparison.
|
|
58
|
+
#ComparisonResult: TypeAlias = Union[ bool, NotImplementedType ]
|
|
59
|
+
ComparisonResult: TypeAlias = bool
|
|
60
|
+
|
|
61
|
+
DictionaryNominativeArgument: TypeAlias = Annotation[
|
|
62
|
+
Any,
|
|
63
|
+
Doc(
|
|
64
|
+
'Zero or more keyword arguments from which to initialize '
|
|
65
|
+
'dictionary data.' )
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
# TODO: Support taking our dictionaries, themselves, as arguments.
|
|
69
|
+
# Supposed to work via structural typing, but must match protocol.
|
|
70
|
+
# https://github.com/python/mypy/issues/2922
|
|
71
|
+
# https://github.com/python/mypy/issues/2922#issuecomment-1186587232
|
|
72
|
+
# https://github.com/python/typing/discussions/1127#discussioncomment-2538837
|
|
73
|
+
# https://mypy.readthedocs.io/en/latest/protocols.html
|
|
74
|
+
DictionaryPositionalArgument: TypeAlias = Annotation[
|
|
75
|
+
Union[ Mapping[ Hashable, Any ], Iterable[ Tuple[ Hashable, Any] ] ],
|
|
76
|
+
Doc(
|
|
77
|
+
'Zero or more iterables from which to initialize dictionary data. '
|
|
78
|
+
'Each iterable must be dictionary or sequence of key-value pairs. '
|
|
79
|
+
'Duplicate keys will result in an error.' )
|
|
80
|
+
]
|
|
81
|
+
|
|
82
|
+
DictionaryProducer: TypeAlias = Annotation[
|
|
83
|
+
Callable[ [ ], Any ],
|
|
84
|
+
Doc( 'Callable which produces values for absent dictionary entries.' )
|
|
85
|
+
]
|
|
86
|
+
|
|
87
|
+
ModuleReclassifier: TypeAlias = Callable[ [ Mapping[ str, Any ] ], None ]
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
__all__ = ( )
|
accretive/_docstrings.py
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# vim: set filetype=python fileencoding=utf-8:
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
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
|
+
#============================================================================#
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
''' Docstrings table for reuse across subpackages. '''
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
from types import MappingProxyType as _DictionaryProxy
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
TABLE = _DictionaryProxy( {
|
|
28
|
+
|
|
29
|
+
'abc attributes exemption': '''
|
|
30
|
+
Derived from and compatible with :py:class:`abc.ABCMeta`. The
|
|
31
|
+
``__abstractmethods__`` class attribute and the class attributes, whose names
|
|
32
|
+
start with ``_abc_``, are exempt from the accretion mechanism so that the
|
|
33
|
+
internal method abstraction machinery can function correctly.
|
|
34
|
+
''',
|
|
35
|
+
|
|
36
|
+
'class attributes accretion': '''
|
|
37
|
+
Prevents reassignment or deletion of class attributes after they have been
|
|
38
|
+
assigned. Only assignment of new class attributes is permitted.
|
|
39
|
+
''',
|
|
40
|
+
|
|
41
|
+
'class attributes concealment': '''
|
|
42
|
+
By default, all class attributes, whose names do not start with ``_``, are
|
|
43
|
+
returned from an invocation of :py:func:`dir`. Additional class attributes can
|
|
44
|
+
be returned, if the ``_class_attribute_visibility_includes_`` attribute is
|
|
45
|
+
provided on a subclass.
|
|
46
|
+
''',
|
|
47
|
+
|
|
48
|
+
'description of class factory class': '''
|
|
49
|
+
Derived from :py:class:`type`, this is a metaclass. A metaclass is a class
|
|
50
|
+
factory class. I.e., it is a class that produces other classes as its
|
|
51
|
+
instances.
|
|
52
|
+
''',
|
|
53
|
+
|
|
54
|
+
'description of module': '''
|
|
55
|
+
Derived from :py:class:`types.ModuleType`, this class is suitable for use as a
|
|
56
|
+
Python module class.
|
|
57
|
+
''',
|
|
58
|
+
|
|
59
|
+
'description of namespace': '''
|
|
60
|
+
A namespace is an object, whose attributes can be determined from iterables and
|
|
61
|
+
keyword arguments, at initialization time. The string representation of the
|
|
62
|
+
namespace object reflects its current instance attributes. Modeled after
|
|
63
|
+
:py:class:`types.SimpleNamespace`.
|
|
64
|
+
''',
|
|
65
|
+
|
|
66
|
+
'dictionary entries accretion': '''
|
|
67
|
+
Prevents alteration or removal of dictionary entries after they have been
|
|
68
|
+
added. Only addition of new dictionary entries is permitted.
|
|
69
|
+
''',
|
|
70
|
+
|
|
71
|
+
'dictionary entries production': '''
|
|
72
|
+
When an attempt to access a missing entry is made, then the entry is added with
|
|
73
|
+
a default value. Modeled after :py:class:`collections.defaultdict`.
|
|
74
|
+
''',
|
|
75
|
+
|
|
76
|
+
'instance attributes accretion': '''
|
|
77
|
+
Prevents reassignment or deletion of instance attributes after they have been
|
|
78
|
+
assigned. Only assignment of new instance attributes is permitted.
|
|
79
|
+
''',
|
|
80
|
+
|
|
81
|
+
'instance attributes concealment': '''
|
|
82
|
+
By default, all instance attributes, whose names do not start with ``_``, are
|
|
83
|
+
returned from an invocation of :py:func:`dir`. Additional instance attributes
|
|
84
|
+
can be returned, if the ``_attribute_visibility_includes_`` attribute is
|
|
85
|
+
provided on a subclass.
|
|
86
|
+
''',
|
|
87
|
+
|
|
88
|
+
'module attributes accretion': '''
|
|
89
|
+
Prevents reassignment or deletion of module attributes after they have been
|
|
90
|
+
assigned. Only assignment of new module attributes is permitted.
|
|
91
|
+
''',
|
|
92
|
+
|
|
93
|
+
'module attributes concealment': '''
|
|
94
|
+
By default, all module attributes, whose names do not start with ``_``, are
|
|
95
|
+
returned from an invocation of :py:func:`dir`. Additional module attributes
|
|
96
|
+
can be returned, if the ``_attribute_visibility_includes_`` attribute is
|
|
97
|
+
provided on a subclass.
|
|
98
|
+
''',
|
|
99
|
+
|
|
100
|
+
'protection of class': '''
|
|
101
|
+
Enforcement of attributes accretion on this class, itself, is in effect.
|
|
102
|
+
''',
|
|
103
|
+
|
|
104
|
+
'protection of class factory class': '''
|
|
105
|
+
Enforcement of attributes accretion on this metaclass, itself, is in effect.
|
|
106
|
+
''',
|
|
107
|
+
|
|
108
|
+
'protection of module class': '''
|
|
109
|
+
Enforcement of attributes accretion on this module class, itself, is in effect.
|
|
110
|
+
''',
|
|
111
|
+
|
|
112
|
+
'subpackage behavior: attributes accretion': '''
|
|
113
|
+
Accretive data structures can grow at any time but can never shrink. An
|
|
114
|
+
accretive dictionary accepts new entires, but cannot have existing entries
|
|
115
|
+
altered or removed. Similarly, an accretive namespace accepts new attributes,
|
|
116
|
+
but cannot have existing attributes assigned to new values or deleted.
|
|
117
|
+
''',
|
|
118
|
+
|
|
119
|
+
'subpackage behavior: attributes concealment': '''
|
|
120
|
+
Data structures, provided by this subpackage, have concealed attributes.
|
|
121
|
+
Concealed attributes do not appear in listings via the :py:func:`dir` builtin
|
|
122
|
+
function. By default, only attributes names, which do not start with ``_`` are
|
|
123
|
+
made visible, but additional attributes can be included if they are listed on a
|
|
124
|
+
particular class attribute that the concealer honors.
|
|
125
|
+
''',
|
|
126
|
+
|
|
127
|
+
'subpackage behavior: protection of classes': '''
|
|
128
|
+
Classes of data structures, provided by this subpackage, have protected
|
|
129
|
+
attributes. Attributes are accreted on these classes and cannot be reassigned
|
|
130
|
+
or deleted.
|
|
131
|
+
''',
|
|
132
|
+
|
|
133
|
+
} )
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
__all__ = ( )
|
accretive/aaliases.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# vim: set filetype=python fileencoding=utf-8:
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
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
|
+
#============================================================================#
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
''' Abbreviated aliases to accretive data structures.
|
|
22
|
+
|
|
23
|
+
Similar to Python builtins.
|
|
24
|
+
'''
|
|
25
|
+
|
|
26
|
+
# ruff: noqa: F401
|
|
27
|
+
# pylint: disable=unused-import
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
from . import __
|
|
31
|
+
from .classes import ABCFactory as acabcmeta, Class as actype
|
|
32
|
+
from .dictionaries import (
|
|
33
|
+
Dictionary as acdict,
|
|
34
|
+
ProducerDictionary as acdefaultdict,
|
|
35
|
+
)
|
|
36
|
+
from .modules import Module as acmodule
|
|
37
|
+
from .namespaces import Namespace as acnamespace
|
|
38
|
+
from .objects import Object as acobject
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
__all__ = __.discover_public_attributes( globals( ) )
|
accretive/classes.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# vim: set filetype=python fileencoding=utf-8:
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
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
|
+
#============================================================================#
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
''' Accretive classes. '''
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
from __future__ import annotations
|
|
25
|
+
|
|
26
|
+
from . import __
|
|
27
|
+
from . import _annotations as _a
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class Class( type ):
|
|
31
|
+
''' Accretive classes. '''
|
|
32
|
+
|
|
33
|
+
def __new__(
|
|
34
|
+
factory: _a.Type[ type ],
|
|
35
|
+
name: str,
|
|
36
|
+
bases: _a.Tuple[ type, ... ],
|
|
37
|
+
namespace: _a.MutableMapping[ str, _a.Any ],
|
|
38
|
+
docstring: str = None,
|
|
39
|
+
**nomargs: _a.Any
|
|
40
|
+
) -> Class:
|
|
41
|
+
if docstring: namespace[ '__doc__' ] = docstring
|
|
42
|
+
return _a.cast(
|
|
43
|
+
Class,
|
|
44
|
+
super( ).__new__( factory, name, bases, namespace, **nomargs ) )
|
|
45
|
+
|
|
46
|
+
def __delattr__( class_, name: str ) -> None:
|
|
47
|
+
from .exceptions import IndelibleAttributeError
|
|
48
|
+
raise IndelibleAttributeError( name )
|
|
49
|
+
|
|
50
|
+
def __setattr__( class_, name: str, value: _a.Any ) -> None:
|
|
51
|
+
from .exceptions import IndelibleAttributeError
|
|
52
|
+
if hasattr( class_, name ): raise IndelibleAttributeError( name )
|
|
53
|
+
# Note: CPython cell class is not set in all circumstances.
|
|
54
|
+
# When it is, then we use two-argument form.
|
|
55
|
+
# Else, we use three-argument form.
|
|
56
|
+
try: super( ).__setattr__( name, value )
|
|
57
|
+
except TypeError:
|
|
58
|
+
super( ).__setattr__( # type: ignore[call-arg]
|
|
59
|
+
class_, name, value ) # type: ignore[arg-type]
|
|
60
|
+
|
|
61
|
+
Class.__doc__ = __.generate_docstring(
|
|
62
|
+
Class,
|
|
63
|
+
'description of class factory class',
|
|
64
|
+
'class attributes accretion'
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class ABCFactory( Class, __.ABCFactory ): # type: ignore[misc]
|
|
69
|
+
''' Accretive abstract base classes (ABC). '''
|
|
70
|
+
|
|
71
|
+
def __setattr__( class_, name: str, value: _a.Any ) -> None:
|
|
72
|
+
# Bypass accretion machinery for ABC magic attributes.
|
|
73
|
+
if ( # pylint: disable=magic-value-comparison
|
|
74
|
+
'__abstractmethods__' == name or name.startswith( '_abc_' )
|
|
75
|
+
):
|
|
76
|
+
__.ABCFactory.__setattr__( class_, name, value )
|
|
77
|
+
return
|
|
78
|
+
super( ).__setattr__( name, value )
|
|
79
|
+
|
|
80
|
+
ABCFactory.__doc__ = __.generate_docstring(
|
|
81
|
+
ABCFactory,
|
|
82
|
+
'description of class factory class',
|
|
83
|
+
'class attributes accretion',
|
|
84
|
+
'abc attributes exemption',
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
__all__ = __.discover_public_attributes( globals( ) )
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# vim: set filetype=python fileencoding=utf-8:
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
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
|
+
#============================================================================#
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
''' Protected accretive data structures with attributes concealment. '''
|
|
22
|
+
|
|
23
|
+
# ruff: noqa: F401,F403
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
from .. import __
|
|
27
|
+
from . import aaliases
|
|
28
|
+
from . import classes
|
|
29
|
+
from . import dictionaries
|
|
30
|
+
from . import modules
|
|
31
|
+
from . import namespaces
|
|
32
|
+
from . import objects
|
|
33
|
+
from . import qaliases
|
|
34
|
+
|
|
35
|
+
from .classes import *
|
|
36
|
+
from .dictionaries import *
|
|
37
|
+
from .modules import *
|
|
38
|
+
from .namespaces import *
|
|
39
|
+
from .objects import *
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
__doc__ = __.generate_docstring(
|
|
43
|
+
__.Docstring( __doc__ ),
|
|
44
|
+
'subpackage behavior: attributes accretion',
|
|
45
|
+
'subpackage behavior: attributes concealment',
|
|
46
|
+
'subpackage behavior: protection of classes' )
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
__all__ = __.discover_public_attributes( globals( ) )
|