Coverage for sources/classcore/standard/classes.py: 100%
67 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-07-20 04:08 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-07-20 04:08 +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_abc_class_mutables = (
31 '_abc_cache',
32 '_abc_negative_cache',
33 '_abc_negative_cache_version',
34 '_abc_registry',
35)
36_dynadoc_configuration = (
37 _dynadoc.produce_dynadoc_configuration( table = __.fragments ) )
38_class_factory = __.funct.partial(
39 _decorators.class_factory, dynadoc_configuration = _dynadoc_configuration )
42class ClassFactoryExtraArguments( __.typx.TypedDict, total = False ):
43 ''' Extra arguments accepted by standard metaclasses. '''
45 class_mutables: _nomina.BehaviorExclusionVerifiersOmni
46 class_visibles: _nomina.BehaviorExclusionVerifiersOmni
47 dynadoc_configuration: _nomina.DynadocConfiguration
48 instances_assigner_core: _nomina.AssignerCore
49 instances_deleter_core: _nomina.DeleterCore
50 instances_surveyor_core: _nomina.SurveyorCore
51 instances_ignore_init_arguments: bool
52 instances_mutables: _nomina.BehaviorExclusionVerifiersOmni
53 instances_visibles: _nomina.BehaviorExclusionVerifiersOmni
56@_class_factory( )
57class Class( type ):
58 ''' Metaclass for standard classes. '''
60 _dynadoc_fragments_ = (
61 'cfc class conceal', 'cfc class protect', 'cfc dynadoc',
62 'cfc instance conceal', 'cfc instance protect' )
64 def __new__( # Typechecker stub.
65 clscls: type[ __.T ],
66 name: str,
67 bases: tuple[ type, ... ],
68 namespace: dict[ str, __.typx.Any ], *,
69 decorators: _nomina.Decorators[ __.T ] = ( ),
70 **arguments: __.typx.Unpack[ ClassFactoryExtraArguments ],
71 ) -> __.T:
72 return super( ).__new__( clscls, name, bases, namespace )
75@_class_factory( )
76@__.typx.dataclass_transform( frozen_default = True, kw_only_default = True )
77class Dataclass( type ):
78 ''' Metaclass for standard dataclasses. '''
80 _dynadoc_fragments_ = (
81 'cfc produce dataclass',
82 'cfc class conceal', 'cfc class protect', 'cfc dynadoc',
83 'cfc instance conceal', 'cfc instance protect' )
85 def __new__( # Typechecker stub.
86 clscls: type[ __.T ],
87 name: str,
88 bases: tuple[ type, ... ],
89 namespace: dict[ str, __.typx.Any ], *,
90 decorators: _nomina.Decorators[ __.T ] = ( ),
91 **arguments: __.typx.Unpack[ ClassFactoryExtraArguments ],
92 ) -> __.T:
93 return super( ).__new__( clscls, name, bases, namespace )
96@_class_factory( )
97@__.typx.dataclass_transform( kw_only_default = True )
98class DataclassMutable( type ):
99 ''' Metaclass for dataclasses with mutable instance attributes. '''
101 _dynadoc_fragments_ = (
102 'cfc produce dataclass',
103 'cfc class conceal', 'cfc class protect', 'cfc dynadoc',
104 'cfc instance conceal' )
106 def __new__( # Typechecker stub.
107 clscls: type[ __.T ],
108 name: str,
109 bases: tuple[ type, ... ],
110 namespace: dict[ str, __.typx.Any ], *,
111 decorators: _nomina.Decorators[ __.T ] = ( ),
112 **arguments: __.typx.Unpack[ ClassFactoryExtraArguments ],
113 ) -> __.T:
114 return super( ).__new__( clscls, name, bases, namespace )
117@_class_factory( )
118class ProtocolClass( type( __.typx.Protocol ) ):
119 ''' Metaclass for standard protocol classes. '''
121 _dynadoc_fragments_ = (
122 'cfc produce protocol class',
123 'cfc class conceal', 'cfc class protect', 'cfc dynadoc',
124 'cfc instance conceal', 'cfc instance protect' )
126 def __new__( # Typechecker stub.
127 clscls: type[ __.T ],
128 name: str,
129 bases: tuple[ type, ... ],
130 namespace: dict[ str, __.typx.Any ], *,
131 decorators: _nomina.Decorators[ __.T ] = ( ),
132 **arguments: __.typx.Unpack[ ClassFactoryExtraArguments ],
133 ) -> __.T:
134 return super( ).__new__( clscls, name, bases, namespace )
137@_class_factory( )
138@__.typx.dataclass_transform( frozen_default = True, kw_only_default = True )
139class ProtocolDataclass( type( __.typx.Protocol ) ):
140 ''' Metaclass for standard protocol dataclasses. '''
142 _dynadoc_fragments_ = (
143 'cfc produce protocol class', 'cfc produce dataclass',
144 'cfc class conceal', 'cfc class protect', 'cfc dynadoc',
145 'cfc instance conceal', 'cfc instance protect' )
147 def __new__( # Typechecker stub.
148 clscls: type[ __.T ],
149 name: str,
150 bases: tuple[ type, ... ],
151 namespace: dict[ str, __.typx.Any ], *,
152 decorators: _nomina.Decorators[ __.T ] = ( ),
153 **arguments: __.typx.Unpack[ ClassFactoryExtraArguments ],
154 ) -> __.T:
155 return super( ).__new__( clscls, name, bases, namespace )
158@_class_factory( )
159@__.typx.dataclass_transform( kw_only_default = True )
160class ProtocolDataclassMutable( type( __.typx.Protocol ) ):
161 ''' Metaclass for protocol dataclasses with mutable instance attributes.
162 '''
164 _dynadoc_fragments_ = (
165 'cfc produce protocol class', 'cfc produce dataclass',
166 'cfc class conceal', 'cfc class protect', 'cfc dynadoc',
167 'cfc instance conceal' )
169 def __new__( # Typechecker stub.
170 clscls: type[ __.T ],
171 name: str,
172 bases: tuple[ type, ... ],
173 namespace: dict[ str, __.typx.Any ], *,
174 decorators: _nomina.Decorators[ __.T ] = ( ),
175 **arguments: __.typx.Unpack[ ClassFactoryExtraArguments ],
176 ) -> __.T:
177 return super( ).__new__( clscls, name, bases, namespace )
180class Object( metaclass = Class ):
181 ''' Standard base class. '''
183 _dynadoc_fragments_ = (
184 'class concealment', 'class protection', 'class dynadoc',
185 'class instance conceal', 'class instance protect' )
188class ObjectMutable( metaclass = Class, instances_mutables = '*' ):
189 ''' Base class with mutable instance attributes. '''
191 _dynadoc_fragments_ = (
192 'class concealment', 'class protection', 'class dynadoc',
193 'class instance conceal' )
196class DataclassObject( metaclass = Dataclass ):
197 ''' Standard base dataclass. '''
199 _dynadoc_fragments_ = (
200 'dataclass',
201 'class concealment', 'class protection', 'class dynadoc',
202 'class instance conceal', 'class instance protect' )
205class DataclassObjectMutable( metaclass = DataclassMutable ):
206 ''' Base dataclass with mutable instance attributes. '''
208 _dynadoc_fragments_ = (
209 'dataclass',
210 'class concealment', 'class protection', 'class dynadoc',
211 'class instance conceal' )
214class Protocol(
215 __.typx.Protocol,
216 metaclass = ProtocolClass,
217 class_mutables = _abc_class_mutables,
218):
219 ''' Standard base protocol class. '''
221 _dynadoc_fragments_ = (
222 'protocol class',
223 'class concealment', 'class protection', 'class dynadoc',
224 'class instance conceal', 'class instance protect' )
227class ProtocolMutable(
228 __.typx.Protocol,
229 metaclass = ProtocolClass,
230 class_mutables = _abc_class_mutables,
231 instances_mutables = '*',
232):
233 ''' Base protocol class with mutable instance attributes. '''
235 _dynadoc_fragments_ = (
236 'protocol class',
237 'class concealment', 'class protection', 'class dynadoc',
238 'class instance conceal' )
241class DataclassProtocol(
242 __.typx.Protocol,
243 metaclass = ProtocolDataclass,
244 class_mutables = _abc_class_mutables,
245):
246 ''' Standard base protocol dataclass. '''
248 _dynadoc_fragments_ = (
249 'dataclass', 'protocol class',
250 'class concealment', 'class protection', 'class dynadoc',
251 'class instance conceal', 'class instance protect' )
254class DataclassProtocolMutable(
255 __.typx.Protocol,
256 metaclass = ProtocolDataclassMutable,
257 class_mutables = _abc_class_mutables,
258):
259 ''' Base protocol dataclass with mutable instance attributes. '''
261 _dynadoc_fragments_ = (
262 'dataclass', 'protocol class',
263 'class concealment', 'class protection', 'class dynadoc',
264 'class instance conceal' )