Coverage for sources/classcore/standard/classes.py: 100%

66 statements  

« prev     ^ index     » next       coverage.py v7.9.2, created at 2025-07-23 13:53 +0000

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 classes and class factories. ''' 

22 

23 

24from . import __ 

25from . import decorators as _decorators 

26from . import dynadoc as _dynadoc 

27from . import nomina as _nomina 

28 

29 

30_dynadoc_configuration = ( 

31 _dynadoc.produce_dynadoc_configuration( table = __.fragments ) ) 

32_class_factory = __.funct.partial( 

33 _decorators.class_factory, dynadoc_configuration = _dynadoc_configuration ) 

34 

35 

36class ClassFactoryExtraArguments( __.typx.TypedDict, total = False ): 

37 ''' Extra arguments accepted by standard metaclasses. ''' 

38 

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 

48 

49 

50@_class_factory( ) 

51class Class( type ): 

52 ''' Metaclass for standard classes. ''' 

53 

54 _dynadoc_fragments_ = ( 

55 'cfc class conceal', 'cfc class protect', 'cfc dynadoc', 

56 'cfc instance conceal', 'cfc instance protect' ) 

57 

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 ) 

67 

68 

69@_class_factory( ) 

70@__.typx.dataclass_transform( frozen_default = True, kw_only_default = True ) 

71class Dataclass( type ): 

72 ''' Metaclass for standard dataclasses. ''' 

73 

74 _dynadoc_fragments_ = ( 

75 'cfc produce dataclass', 

76 'cfc class conceal', 'cfc class protect', 'cfc dynadoc', 

77 'cfc instance conceal', 'cfc instance protect' ) 

78 

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 ) 

88 

89 

90@_class_factory( ) 

91@__.typx.dataclass_transform( kw_only_default = True ) 

92class DataclassMutable( type ): 

93 ''' Metaclass for dataclasses with mutable instance attributes. ''' 

94 

95 _dynadoc_fragments_ = ( 

96 'cfc produce dataclass', 

97 'cfc class conceal', 'cfc class protect', 'cfc dynadoc', 

98 'cfc instance conceal' ) 

99 

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 ) 

109 

110 

111@_class_factory( ) 

112class ProtocolClass( type( __.typx.Protocol ) ): 

113 ''' Metaclass for standard protocol classes. ''' 

114 

115 _dynadoc_fragments_ = ( 

116 'cfc produce protocol class', 

117 'cfc class conceal', 'cfc class protect', 'cfc dynadoc', 

118 'cfc instance conceal', 'cfc instance protect' ) 

119 

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 ) 

129 

130 

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. ''' 

135 

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' ) 

140 

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 ) 

150 

151 

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 ''' 

157 

158 _dynadoc_fragments_ = ( 

159 'cfc produce protocol class', 'cfc produce dataclass', 

160 'cfc class conceal', 'cfc class protect', 'cfc dynadoc', 

161 'cfc instance conceal' ) 

162 

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 ) 

172 

173 

174class Object( metaclass = Class ): 

175 ''' Standard base class. ''' 

176 

177 _dynadoc_fragments_ = ( 

178 'class concealment', 'class protection', 'class dynadoc', 

179 'class instance conceal', 'class instance protect' ) 

180 

181 

182class ObjectMutable( metaclass = Class, instances_mutables = '*' ): 

183 ''' Base class with mutable instance attributes. ''' 

184 

185 _dynadoc_fragments_ = ( 

186 'class concealment', 'class protection', 'class dynadoc', 

187 'class instance conceal' ) 

188 

189 

190class DataclassObject( metaclass = Dataclass ): 

191 ''' Standard base dataclass. ''' 

192 

193 _dynadoc_fragments_ = ( 

194 'dataclass', 

195 'class concealment', 'class protection', 'class dynadoc', 

196 'class instance conceal', 'class instance protect' ) 

197 

198 

199class DataclassObjectMutable( metaclass = DataclassMutable ): 

200 ''' Base dataclass with mutable instance attributes. ''' 

201 

202 _dynadoc_fragments_ = ( 

203 'dataclass', 

204 'class concealment', 'class protection', 'class dynadoc', 

205 'class instance conceal' ) 

206 

207 

208class Protocol( __.typx.Protocol, metaclass = ProtocolClass ): 

209 ''' Standard base protocol class. ''' 

210 

211 _dynadoc_fragments_ = ( 

212 'protocol class', 

213 'class concealment', 'class protection', 'class dynadoc', 

214 'class instance conceal', 'class instance protect' ) 

215 

216 

217class ProtocolMutable( 

218 __.typx.Protocol, metaclass = ProtocolClass, instances_mutables = '*' 

219): 

220 ''' Base protocol class with mutable instance attributes. ''' 

221 

222 _dynadoc_fragments_ = ( 

223 'protocol class', 

224 'class concealment', 'class protection', 'class dynadoc', 

225 'class instance conceal' ) 

226 

227 

228class DataclassProtocol( 

229 __.typx.Protocol, metaclass = ProtocolDataclass, 

230): 

231 ''' Standard base protocol dataclass. ''' 

232 

233 _dynadoc_fragments_ = ( 

234 'dataclass', 'protocol class', 

235 'class concealment', 'class protection', 'class dynadoc', 

236 'class instance conceal', 'class instance protect' ) 

237 

238 

239class DataclassProtocolMutable( 

240 __.typx.Protocol, metaclass = ProtocolDataclassMutable, 

241): 

242 ''' Base protocol dataclass with mutable instance attributes. ''' 

243 

244 _dynadoc_fragments_ = ( 

245 'dataclass', 'protocol class', 

246 'class concealment', 'class protection', 'class dynadoc', 

247 'class instance conceal' )