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

62 statements  

« prev     ^ index     » next       coverage.py v7.8.2, created at 2025-06-05 22:50 +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 _CfcExtraArguments( __.typx.TypedDict, total = False ): 

37 

38 class_mutables: _nomina.BehaviorExclusionVerifiersOmni 

39 class_visibles: _nomina.BehaviorExclusionVerifiersOmni 

40 dynadoc_configuration: _nomina.DynadocConfiguration 

41 instances_mutables: _nomina.BehaviorExclusionVerifiersOmni 

42 instances_visibles: _nomina.BehaviorExclusionVerifiersOmni 

43 

44 

45@_class_factory( ) 

46class Class( type ): 

47 ''' Metaclass for standard classes. ''' 

48 

49 _dynadoc_fragments_ = ( 

50 'cfc class conceal', 'cfc class protect', 'cfc dynadoc', 

51 'cfc instance conceal', 'cfc instance protect' ) 

52 

53 def __new__( # Typechecker stub. 

54 clscls: type[ __.T ], 

55 name: str, 

56 bases: tuple[ type, ... ], 

57 namespace: dict[ str, __.typx.Any ], *, 

58 decorators: _nomina.Decorators[ __.T ] = ( ), 

59 **arguments: __.typx.Unpack[ _CfcExtraArguments ], 

60 ) -> __.T: 

61 return super( ).__new__( clscls, name, bases, namespace ) 

62 

63 

64@_class_factory( ) 

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

66class Dataclass( type ): 

67 ''' Metaclass for standard dataclasses. ''' 

68 

69 _dynadoc_fragments_ = ( 

70 'cfc produce dataclass', 

71 'cfc class conceal', 'cfc class protect', 'cfc dynadoc', 

72 'cfc instance conceal', 'cfc instance protect' ) 

73 

74 def __new__( # Typechecker stub. 

75 clscls: type[ __.T ], 

76 name: str, 

77 bases: tuple[ type, ... ], 

78 namespace: dict[ str, __.typx.Any ], *, 

79 decorators: _nomina.Decorators[ __.T ] = ( ), 

80 **arguments: __.typx.Unpack[ _CfcExtraArguments ], 

81 ) -> __.T: 

82 return super( ).__new__( clscls, name, bases, namespace ) 

83 

84 

85@_class_factory( ) 

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

87class DataclassMutable( type ): 

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

89 

90 _dynadoc_fragments_ = ( 

91 'cfc produce dataclass', 

92 'cfc class conceal', 'cfc class protect', 'cfc dynadoc', 

93 'cfc instance conceal' ) 

94 

95 def __new__( # Typechecker stub. 

96 clscls: type[ __.T ], 

97 name: str, 

98 bases: tuple[ type, ... ], 

99 namespace: dict[ str, __.typx.Any ], *, 

100 decorators: _nomina.Decorators[ __.T ] = ( ), 

101 **arguments: __.typx.Unpack[ _CfcExtraArguments ], 

102 ) -> __.T: 

103 return super( ).__new__( clscls, name, bases, namespace ) 

104 

105 

106@_class_factory( ) 

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

108 ''' Metaclass for standard protocol classes. ''' 

109 

110 _dynadoc_fragments_ = ( 

111 'cfc produce protocol class', 

112 'cfc class conceal', 'cfc class protect', 'cfc dynadoc', 

113 'cfc instance conceal', 'cfc instance protect' ) 

114 

115 def __new__( # Typechecker stub. 

116 clscls: type[ __.T ], 

117 name: str, 

118 bases: tuple[ type, ... ], 

119 namespace: dict[ str, __.typx.Any ], *, 

120 decorators: _nomina.Decorators[ __.T ] = ( ), 

121 **arguments: __.typx.Unpack[ _CfcExtraArguments ], 

122 ) -> __.T: 

123 return super( ).__new__( clscls, name, bases, namespace ) 

124 

125 

126@_class_factory( ) 

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

128class ProtocolDataclass( type( __.typx.Protocol ) ): 

129 ''' Metaclass for standard protocol dataclasses. ''' 

130 

131 _dynadoc_fragments_ = ( 

132 'cfc produce protocol class', 'cfc produce dataclass', 

133 'cfc class conceal', 'cfc class protect', 'cfc dynadoc', 

134 'cfc instance conceal', 'cfc instance protect' ) 

135 

136 def __new__( # Typechecker stub. 

137 clscls: type[ __.T ], 

138 name: str, 

139 bases: tuple[ type, ... ], 

140 namespace: dict[ str, __.typx.Any ], *, 

141 decorators: _nomina.Decorators[ __.T ] = ( ), 

142 **arguments: __.typx.Unpack[ _CfcExtraArguments ], 

143 ) -> __.T: 

144 return super( ).__new__( clscls, name, bases, namespace ) 

145 

146 

147@_class_factory( ) 

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

149class ProtocolDataclassMutable( type( __.typx.Protocol ) ): 

150 ''' Metaclass for protocol dataclasses with mutable instance attributes. 

151 ''' 

152 

153 _dynadoc_fragments_ = ( 

154 'cfc produce protocol class', 'cfc produce dataclass', 

155 'cfc class conceal', 'cfc class protect', 'cfc dynadoc', 

156 'cfc instance conceal' ) 

157 

158 def __new__( # Typechecker stub. 

159 clscls: type[ __.T ], 

160 name: str, 

161 bases: tuple[ type, ... ], 

162 namespace: dict[ str, __.typx.Any ], *, 

163 decorators: _nomina.Decorators[ __.T ] = ( ), 

164 **arguments: __.typx.Unpack[ _CfcExtraArguments ], 

165 ) -> __.T: 

166 return super( ).__new__( clscls, name, bases, namespace ) 

167 

168 

169class Object( metaclass = Class ): 

170 ''' Standard base class. ''' 

171 

172 _dynadoc_fragments_ = ( 

173 'class concealment', 'class protection', 'class dynadoc', 

174 'class instance conceal', 'class instance protect' ) 

175 

176 

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

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

179 

180 _dynadoc_fragments_ = ( 

181 'class concealment', 'class protection', 'class dynadoc', 

182 'class instance conceal' ) 

183 

184 

185class DataclassObject( metaclass = Dataclass ): 

186 ''' Standard base dataclass. ''' 

187 

188 _dynadoc_fragments_ = ( 

189 'dataclass', 

190 'class concealment', 'class protection', 'class dynadoc', 

191 'class instance conceal', 'class instance protect' ) 

192 

193 

194class DataclassObjectMutable( metaclass = DataclassMutable ): 

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

196 

197 _dynadoc_fragments_ = ( 

198 'dataclass', 

199 'class concealment', 'class protection', 'class dynadoc', 

200 'class instance conceal' ) 

201 

202 

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

204 ''' Standard base protocol class. ''' 

205 

206 _dynadoc_fragments_ = ( 

207 'protocol class', 

208 'class concealment', 'class protection', 'class dynadoc', 

209 'class instance conceal', 'class instance protect' ) 

210 

211 

212class ProtocolMutable( 

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

214): 

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

216 

217 _dynadoc_fragments_ = ( 

218 'protocol class', 

219 'class concealment', 'class protection', 'class dynadoc', 

220 'class instance conceal' ) 

221 

222 

223class DataclassProtocol( 

224 __.typx.Protocol, metaclass = ProtocolDataclass, 

225): 

226 ''' Standard base protocol dataclass. ''' 

227 

228 _dynadoc_fragments_ = ( 

229 'dataclass', 'protocol class', 

230 'class concealment', 'class protection', 'class dynadoc', 

231 'class instance conceal', 'class instance protect' ) 

232 

233 

234class DataclassProtocolMutable( 

235 __.typx.Protocol, metaclass = ProtocolDataclassMutable, 

236): 

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

238 

239 _dynadoc_fragments_ = ( 

240 'dataclass', 'protocol class', 

241 'class concealment', 'class protection', 'class dynadoc', 

242 'class instance conceal' )