Coverage for sources/classcore/standard/classes.py: 100%
66 statements
« prev ^ index » next coverage.py v7.10.7, created at 2025-09-25 13:22 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2025-09-25 13:22 +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''' Standard classes and class factories. '''
24from . import __
25from . import decorators as _decorators
26from . import dynadoc as _dynadoc
27from . import nomina as _nomina
30_dynadoc_configuration = (
31 _dynadoc.produce_dynadoc_configuration( table = __.fragments ) )
32_class_factory = __.funct.partial(
33 _decorators.class_factory, dynadoc_configuration = _dynadoc_configuration )
36class ClassFactoryExtraArguments( __.typx.TypedDict, total = False ):
37 ''' Extra arguments accepted by standard metaclasses. '''
39 class_mutables: _nomina.BehaviorExclusionVerifiersOmni
40 class_visibles: _nomina.BehaviorExclusionVerifiersOmni
41 dynadoc_configuration: _nomina.DynadocConfiguration
42 instances_assigner_core: _nomina.AssignerCore
43 instances_deleter_core: _nomina.DeleterCore
44 instances_surveyor_core: _nomina.SurveyorCore
45 instances_ignore_init_arguments: bool
46 instances_mutables: _nomina.BehaviorExclusionVerifiersOmni
47 instances_visibles: _nomina.BehaviorExclusionVerifiersOmni
50@_class_factory( )
51class Class( type ):
52 ''' Metaclass for standard classes. '''
54 _dynadoc_fragments_ = (
55 'cfc class conceal', 'cfc class protect', 'cfc dynadoc',
56 'cfc instance conceal', 'cfc instance protect' )
58 def __new__( # Typechecker stub.
59 clscls: type[ __.T ],
60 name: str,
61 bases: tuple[ type, ... ],
62 namespace: dict[ str, __.typx.Any ], *,
63 decorators: _nomina.Decorators[ __.T ] = ( ),
64 **arguments: __.typx.Unpack[ ClassFactoryExtraArguments ],
65 ) -> __.T:
66 return super( ).__new__( clscls, name, bases, namespace )
69@_class_factory( )
70@__.typx.dataclass_transform( frozen_default = True, kw_only_default = True )
71class Dataclass( type ):
72 ''' Metaclass for standard dataclasses. '''
74 _dynadoc_fragments_ = (
75 'cfc produce dataclass',
76 'cfc class conceal', 'cfc class protect', 'cfc dynadoc',
77 'cfc instance conceal', 'cfc instance protect' )
79 def __new__( # Typechecker stub.
80 clscls: type[ __.T ],
81 name: str,
82 bases: tuple[ type, ... ],
83 namespace: dict[ str, __.typx.Any ], *,
84 decorators: _nomina.Decorators[ __.T ] = ( ),
85 **arguments: __.typx.Unpack[ ClassFactoryExtraArguments ],
86 ) -> __.T:
87 return super( ).__new__( clscls, name, bases, namespace )
90@_class_factory( )
91@__.typx.dataclass_transform( kw_only_default = True )
92class DataclassMutable( type ):
93 ''' Metaclass for dataclasses with mutable instance attributes. '''
95 _dynadoc_fragments_ = (
96 'cfc produce dataclass',
97 'cfc class conceal', 'cfc class protect', 'cfc dynadoc',
98 'cfc instance conceal' )
100 def __new__( # Typechecker stub.
101 clscls: type[ __.T ],
102 name: str,
103 bases: tuple[ type, ... ],
104 namespace: dict[ str, __.typx.Any ], *,
105 decorators: _nomina.Decorators[ __.T ] = ( ),
106 **arguments: __.typx.Unpack[ ClassFactoryExtraArguments ],
107 ) -> __.T:
108 return super( ).__new__( clscls, name, bases, namespace )
111@_class_factory( )
112class ProtocolClass( type( __.typx.Protocol ) ):
113 ''' Metaclass for standard protocol classes. '''
115 _dynadoc_fragments_ = (
116 'cfc produce protocol class',
117 'cfc class conceal', 'cfc class protect', 'cfc dynadoc',
118 'cfc instance conceal', 'cfc instance protect' )
120 def __new__( # Typechecker stub.
121 clscls: type[ __.T ],
122 name: str,
123 bases: tuple[ type, ... ],
124 namespace: dict[ str, __.typx.Any ], *,
125 decorators: _nomina.Decorators[ __.T ] = ( ),
126 **arguments: __.typx.Unpack[ ClassFactoryExtraArguments ],
127 ) -> __.T:
128 return super( ).__new__( clscls, name, bases, namespace )
131@_class_factory( )
132@__.typx.dataclass_transform( frozen_default = True, kw_only_default = True )
133class ProtocolDataclass( type( __.typx.Protocol ) ):
134 ''' Metaclass for standard protocol dataclasses. '''
136 _dynadoc_fragments_ = (
137 'cfc produce protocol class', 'cfc produce dataclass',
138 'cfc class conceal', 'cfc class protect', 'cfc dynadoc',
139 'cfc instance conceal', 'cfc instance protect' )
141 def __new__( # Typechecker stub.
142 clscls: type[ __.T ],
143 name: str,
144 bases: tuple[ type, ... ],
145 namespace: dict[ str, __.typx.Any ], *,
146 decorators: _nomina.Decorators[ __.T ] = ( ),
147 **arguments: __.typx.Unpack[ ClassFactoryExtraArguments ],
148 ) -> __.T:
149 return super( ).__new__( clscls, name, bases, namespace )
152@_class_factory( )
153@__.typx.dataclass_transform( kw_only_default = True )
154class ProtocolDataclassMutable( type( __.typx.Protocol ) ):
155 ''' Metaclass for protocol dataclasses with mutable instance attributes.
156 '''
158 _dynadoc_fragments_ = (
159 'cfc produce protocol class', 'cfc produce dataclass',
160 'cfc class conceal', 'cfc class protect', 'cfc dynadoc',
161 'cfc instance conceal' )
163 def __new__( # Typechecker stub.
164 clscls: type[ __.T ],
165 name: str,
166 bases: tuple[ type, ... ],
167 namespace: dict[ str, __.typx.Any ], *,
168 decorators: _nomina.Decorators[ __.T ] = ( ),
169 **arguments: __.typx.Unpack[ ClassFactoryExtraArguments ],
170 ) -> __.T:
171 return super( ).__new__( clscls, name, bases, namespace )
174class Object( metaclass = Class ):
175 ''' Standard base class. '''
177 _dynadoc_fragments_ = (
178 'class concealment', 'class protection', 'class dynadoc',
179 'class instance conceal', 'class instance protect' )
182class ObjectMutable( metaclass = Class, instances_mutables = '*' ):
183 ''' Base class with mutable instance attributes. '''
185 _dynadoc_fragments_ = (
186 'class concealment', 'class protection', 'class dynadoc',
187 'class instance conceal' )
190class DataclassObject( metaclass = Dataclass ):
191 ''' Standard base dataclass. '''
193 _dynadoc_fragments_ = (
194 'dataclass',
195 'class concealment', 'class protection', 'class dynadoc',
196 'class instance conceal', 'class instance protect' )
199class DataclassObjectMutable( metaclass = DataclassMutable ):
200 ''' Base dataclass with mutable instance attributes. '''
202 _dynadoc_fragments_ = (
203 'dataclass',
204 'class concealment', 'class protection', 'class dynadoc',
205 'class instance conceal' )
208class Protocol(
209 __.typx.Protocol,
210 metaclass = ProtocolClass,
211 class_mutables = (
212 '_abc_cache',
213 '_abc_negative_cache',
214 '_abc_negative_cache_version',
215 '_abc_registry',
216 ),
217):
218 ''' Standard base protocol class. '''
220 _dynadoc_fragments_ = (
221 'protocol class',
222 'class concealment', 'class protection', 'class dynadoc',
223 'class instance conceal', 'class instance protect' )
226class ProtocolMutable(
227 __.typx.Protocol,
228 metaclass = ProtocolClass,
229 class_mutables = (
230 '_abc_cache',
231 '_abc_negative_cache',
232 '_abc_negative_cache_version',
233 '_abc_registry',
234 ),
235 instances_mutables = '*',
236):
237 ''' Base protocol class with mutable instance attributes. '''
239 _dynadoc_fragments_ = (
240 'protocol class',
241 'class concealment', 'class protection', 'class dynadoc',
242 'class instance conceal' )
245class DataclassProtocol(
246 __.typx.Protocol,
247 metaclass = ProtocolDataclass,
248 class_mutables = (
249 '_abc_cache',
250 '_abc_negative_cache',
251 '_abc_negative_cache_version',
252 '_abc_registry',
253 ),
254):
255 ''' Standard base protocol dataclass. '''
257 _dynadoc_fragments_ = (
258 'dataclass', 'protocol class',
259 'class concealment', 'class protection', 'class dynadoc',
260 'class instance conceal', 'class instance protect' )
263class DataclassProtocolMutable(
264 __.typx.Protocol,
265 metaclass = ProtocolDataclassMutable,
266 class_mutables = (
267 '_abc_cache',
268 '_abc_negative_cache',
269 '_abc_negative_cache_version',
270 '_abc_registry',
271 ),
272):
273 ''' Base protocol dataclass with mutable instance attributes. '''
275 _dynadoc_fragments_ = (
276 'dataclass', 'protocol class',
277 'class concealment', 'class protection', 'class dynadoc',
278 'class instance conceal' )