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

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

40 

41 

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

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

44 

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 

54 

55 

56@_class_factory( ) 

57class Class( type ): 

58 ''' Metaclass for standard classes. ''' 

59 

60 _dynadoc_fragments_ = ( 

61 'cfc class conceal', 'cfc class protect', 'cfc dynadoc', 

62 'cfc instance conceal', 'cfc instance protect' ) 

63 

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 ) 

73 

74 

75@_class_factory( ) 

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

77class Dataclass( type ): 

78 ''' Metaclass for standard dataclasses. ''' 

79 

80 _dynadoc_fragments_ = ( 

81 'cfc produce dataclass', 

82 'cfc class conceal', 'cfc class protect', 'cfc dynadoc', 

83 'cfc instance conceal', 'cfc instance protect' ) 

84 

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 ) 

94 

95 

96@_class_factory( ) 

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

98class DataclassMutable( type ): 

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

100 

101 _dynadoc_fragments_ = ( 

102 'cfc produce dataclass', 

103 'cfc class conceal', 'cfc class protect', 'cfc dynadoc', 

104 'cfc instance conceal' ) 

105 

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 ) 

115 

116 

117@_class_factory( ) 

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

119 ''' Metaclass for standard protocol classes. ''' 

120 

121 _dynadoc_fragments_ = ( 

122 'cfc produce protocol class', 

123 'cfc class conceal', 'cfc class protect', 'cfc dynadoc', 

124 'cfc instance conceal', 'cfc instance protect' ) 

125 

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 ) 

135 

136 

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

141 

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

146 

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 ) 

156 

157 

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

163 

164 _dynadoc_fragments_ = ( 

165 'cfc produce protocol class', 'cfc produce dataclass', 

166 'cfc class conceal', 'cfc class protect', 'cfc dynadoc', 

167 'cfc instance conceal' ) 

168 

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 ) 

178 

179 

180class Object( metaclass = Class ): 

181 ''' Standard base class. ''' 

182 

183 _dynadoc_fragments_ = ( 

184 'class concealment', 'class protection', 'class dynadoc', 

185 'class instance conceal', 'class instance protect' ) 

186 

187 

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

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

190 

191 _dynadoc_fragments_ = ( 

192 'class concealment', 'class protection', 'class dynadoc', 

193 'class instance conceal' ) 

194 

195 

196class DataclassObject( metaclass = Dataclass ): 

197 ''' Standard base dataclass. ''' 

198 

199 _dynadoc_fragments_ = ( 

200 'dataclass', 

201 'class concealment', 'class protection', 'class dynadoc', 

202 'class instance conceal', 'class instance protect' ) 

203 

204 

205class DataclassObjectMutable( metaclass = DataclassMutable ): 

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

207 

208 _dynadoc_fragments_ = ( 

209 'dataclass', 

210 'class concealment', 'class protection', 'class dynadoc', 

211 'class instance conceal' ) 

212 

213 

214class Protocol( 

215 __.typx.Protocol, 

216 metaclass = ProtocolClass, 

217 class_mutables = _abc_class_mutables, 

218): 

219 ''' Standard base protocol class. ''' 

220 

221 _dynadoc_fragments_ = ( 

222 'protocol class', 

223 'class concealment', 'class protection', 'class dynadoc', 

224 'class instance conceal', 'class instance protect' ) 

225 

226 

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

234 

235 _dynadoc_fragments_ = ( 

236 'protocol class', 

237 'class concealment', 'class protection', 'class dynadoc', 

238 'class instance conceal' ) 

239 

240 

241class DataclassProtocol( 

242 __.typx.Protocol, 

243 metaclass = ProtocolDataclass, 

244 class_mutables = _abc_class_mutables, 

245): 

246 ''' Standard base protocol dataclass. ''' 

247 

248 _dynadoc_fragments_ = ( 

249 'dataclass', 'protocol class', 

250 'class concealment', 'class protection', 'class dynadoc', 

251 'class instance conceal', 'class instance protect' ) 

252 

253 

254class DataclassProtocolMutable( 

255 __.typx.Protocol, 

256 metaclass = ProtocolDataclassMutable, 

257 class_mutables = _abc_class_mutables, 

258): 

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

260 

261 _dynadoc_fragments_ = ( 

262 'dataclass', 'protocol class', 

263 'class concealment', 'class protection', 'class dynadoc', 

264 'class instance conceal' )