Coverage for sources/classcore/standard/classes.py: 100%
65 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-07-01 19:09 +0000
« prev ^ index » next coverage.py v7.9.1, created at 2025-07-01 19:09 +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_mutables: _nomina.BehaviorExclusionVerifiersOmni
46 instances_visibles: _nomina.BehaviorExclusionVerifiersOmni
49@_class_factory( )
50class Class( type ):
51 ''' Metaclass for standard classes. '''
53 _dynadoc_fragments_ = (
54 'cfc class conceal', 'cfc class protect', 'cfc dynadoc',
55 'cfc instance conceal', 'cfc instance protect' )
57 def __new__( # Typechecker stub.
58 clscls: type[ __.T ],
59 name: str,
60 bases: tuple[ type, ... ],
61 namespace: dict[ str, __.typx.Any ], *,
62 decorators: _nomina.Decorators[ __.T ] = ( ),
63 **arguments: __.typx.Unpack[ ClassFactoryExtraArguments ],
64 ) -> __.T:
65 return super( ).__new__( clscls, name, bases, namespace )
68@_class_factory( )
69@__.typx.dataclass_transform( frozen_default = True, kw_only_default = True )
70class Dataclass( type ):
71 ''' Metaclass for standard dataclasses. '''
73 _dynadoc_fragments_ = (
74 'cfc produce dataclass',
75 'cfc class conceal', 'cfc class protect', 'cfc dynadoc',
76 'cfc instance conceal', 'cfc instance protect' )
78 def __new__( # Typechecker stub.
79 clscls: type[ __.T ],
80 name: str,
81 bases: tuple[ type, ... ],
82 namespace: dict[ str, __.typx.Any ], *,
83 decorators: _nomina.Decorators[ __.T ] = ( ),
84 **arguments: __.typx.Unpack[ ClassFactoryExtraArguments ],
85 ) -> __.T:
86 return super( ).__new__( clscls, name, bases, namespace )
89@_class_factory( )
90@__.typx.dataclass_transform( kw_only_default = True )
91class DataclassMutable( type ):
92 ''' Metaclass for dataclasses with mutable instance attributes. '''
94 _dynadoc_fragments_ = (
95 'cfc produce dataclass',
96 'cfc class conceal', 'cfc class protect', 'cfc dynadoc',
97 'cfc instance conceal' )
99 def __new__( # Typechecker stub.
100 clscls: type[ __.T ],
101 name: str,
102 bases: tuple[ type, ... ],
103 namespace: dict[ str, __.typx.Any ], *,
104 decorators: _nomina.Decorators[ __.T ] = ( ),
105 **arguments: __.typx.Unpack[ ClassFactoryExtraArguments ],
106 ) -> __.T:
107 return super( ).__new__( clscls, name, bases, namespace )
110@_class_factory( )
111class ProtocolClass( type( __.typx.Protocol ) ):
112 ''' Metaclass for standard protocol classes. '''
114 _dynadoc_fragments_ = (
115 'cfc produce protocol class',
116 'cfc class conceal', 'cfc class protect', 'cfc dynadoc',
117 'cfc instance conceal', 'cfc instance protect' )
119 def __new__( # Typechecker stub.
120 clscls: type[ __.T ],
121 name: str,
122 bases: tuple[ type, ... ],
123 namespace: dict[ str, __.typx.Any ], *,
124 decorators: _nomina.Decorators[ __.T ] = ( ),
125 **arguments: __.typx.Unpack[ ClassFactoryExtraArguments ],
126 ) -> __.T:
127 return super( ).__new__( clscls, name, bases, namespace )
130@_class_factory( )
131@__.typx.dataclass_transform( frozen_default = True, kw_only_default = True )
132class ProtocolDataclass( type( __.typx.Protocol ) ):
133 ''' Metaclass for standard protocol dataclasses. '''
135 _dynadoc_fragments_ = (
136 'cfc produce protocol class', 'cfc produce dataclass',
137 'cfc class conceal', 'cfc class protect', 'cfc dynadoc',
138 'cfc instance conceal', 'cfc instance protect' )
140 def __new__( # Typechecker stub.
141 clscls: type[ __.T ],
142 name: str,
143 bases: tuple[ type, ... ],
144 namespace: dict[ str, __.typx.Any ], *,
145 decorators: _nomina.Decorators[ __.T ] = ( ),
146 **arguments: __.typx.Unpack[ ClassFactoryExtraArguments ],
147 ) -> __.T:
148 return super( ).__new__( clscls, name, bases, namespace )
151@_class_factory( )
152@__.typx.dataclass_transform( kw_only_default = True )
153class ProtocolDataclassMutable( type( __.typx.Protocol ) ):
154 ''' Metaclass for protocol dataclasses with mutable instance attributes.
155 '''
157 _dynadoc_fragments_ = (
158 'cfc produce protocol class', 'cfc produce dataclass',
159 'cfc class conceal', 'cfc class protect', 'cfc dynadoc',
160 'cfc instance conceal' )
162 def __new__( # Typechecker stub.
163 clscls: type[ __.T ],
164 name: str,
165 bases: tuple[ type, ... ],
166 namespace: dict[ str, __.typx.Any ], *,
167 decorators: _nomina.Decorators[ __.T ] = ( ),
168 **arguments: __.typx.Unpack[ ClassFactoryExtraArguments ],
169 ) -> __.T:
170 return super( ).__new__( clscls, name, bases, namespace )
173class Object( metaclass = Class ):
174 ''' Standard base class. '''
176 _dynadoc_fragments_ = (
177 'class concealment', 'class protection', 'class dynadoc',
178 'class instance conceal', 'class instance protect' )
181class ObjectMutable( metaclass = Class, instances_mutables = '*' ):
182 ''' Base class with mutable instance attributes. '''
184 _dynadoc_fragments_ = (
185 'class concealment', 'class protection', 'class dynadoc',
186 'class instance conceal' )
189class DataclassObject( metaclass = Dataclass ):
190 ''' Standard base dataclass. '''
192 _dynadoc_fragments_ = (
193 'dataclass',
194 'class concealment', 'class protection', 'class dynadoc',
195 'class instance conceal', 'class instance protect' )
198class DataclassObjectMutable( metaclass = DataclassMutable ):
199 ''' Base dataclass with mutable instance attributes. '''
201 _dynadoc_fragments_ = (
202 'dataclass',
203 'class concealment', 'class protection', 'class dynadoc',
204 'class instance conceal' )
207class Protocol( __.typx.Protocol, metaclass = ProtocolClass ):
208 ''' Standard base protocol class. '''
210 _dynadoc_fragments_ = (
211 'protocol class',
212 'class concealment', 'class protection', 'class dynadoc',
213 'class instance conceal', 'class instance protect' )
216class ProtocolMutable(
217 __.typx.Protocol, metaclass = ProtocolClass, instances_mutables = '*'
218):
219 ''' Base protocol class with mutable instance attributes. '''
221 _dynadoc_fragments_ = (
222 'protocol class',
223 'class concealment', 'class protection', 'class dynadoc',
224 'class instance conceal' )
227class DataclassProtocol(
228 __.typx.Protocol, metaclass = ProtocolDataclass,
229):
230 ''' Standard base protocol dataclass. '''
232 _dynadoc_fragments_ = (
233 'dataclass', 'protocol class',
234 'class concealment', 'class protection', 'class dynadoc',
235 'class instance conceal', 'class instance protect' )
238class DataclassProtocolMutable(
239 __.typx.Protocol, metaclass = ProtocolDataclassMutable,
240):
241 ''' Base protocol dataclass with mutable instance attributes. '''
243 _dynadoc_fragments_ = (
244 'dataclass', 'protocol class',
245 'class concealment', 'class protection', 'class dynadoc',
246 'class instance conceal' )