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

180 statements  

« prev     ^ index     » next       coverage.py v7.10.7, created at 2025-09-24 19:22 +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 decorators. ''' 

22# TODO? Add attribute value transformer as standard decorator argument. 

23 

24 

25from .. import factories as _factories 

26from .. import utilities as _utilities 

27from ..decorators import ( 

28 decoration_by, 

29 produce_class_construction_decorator, 

30 produce_class_initialization_decorator, 

31) 

32from . import __ 

33from . import behaviors as _behaviors 

34from . import dynadoc as _dynadoc 

35from . import nomina as _nomina 

36 

37 

38_dataclass_core = __.dcls.dataclass( kw_only = True, slots = True ) 

39_dynadoc_configuration = _dynadoc.produce_dynadoc_configuration( ) 

40 

41 

42def prepare_dataclass_for_instances( 

43 cls: type, 

44 decorators: _nomina.DecoratorsMutable[ __.U ], /, *, 

45 attributes_namer: _nomina.AttributesNamer, 

46) -> None: 

47 ''' Annotates dataclass in support of instantiation machinery. ''' 

48 annotations = __.inspect.get_annotations( cls ) 

49 behaviors_name = attributes_namer( 'instance', 'behaviors' ) 

50 # TODO: Only use mangling if not slotted. 

51 # behaviors_name_ = _utilities.mangle_name( cls, behaviors_name ) 

52 behaviors_name_ = behaviors_name 

53 annotations[ behaviors_name_ ] = set[ str ] 

54 setattr( cls, '__annotations__', annotations ) # in case of absence 

55 setattr( cls, behaviors_name_, __.dcls.field( 

56 compare = False, hash = False, init = False, repr = False ) ) 

57 

58 

59def apply_cfc_core_functions( 

60 clscls: type[ __.T ], /, 

61 attributes_namer: _nomina.AttributesNamer, 

62 assigner_core: __.typx.Optional[ _nomina.AssignerCore ] = None, 

63 deleter_core: __.typx.Optional[ _nomina.DeleterCore ] = None, 

64 surveyor_core: __.typx.Optional[ _nomina.SurveyorCore ] = None, 

65) -> None: 

66 ''' Stores core functions on metaclass. ''' 

67 cores = dict( 

68 classes_assigner_core = assigner_core, 

69 classes_deleter_core = deleter_core, 

70 classes_surveyor_core = surveyor_core ) 

71 cores_default = dict( 

72 assigner = _behaviors.assign_attribute_if_mutable, 

73 deleter = _behaviors.delete_attribute_if_mutable, 

74 surveyor = _behaviors.survey_visible_attributes ) 

75 for core_name in ( 'assigner', 'deleter', 'surveyor' ): 

76 core_function = _behaviors.access_core_function( 

77 clscls, 

78 attributes_namer = attributes_namer, 

79 arguments = cores, 

80 level = 'classes', name = core_name, 

81 default = cores_default[ core_name ] ) 

82 core_aname = attributes_namer( 'classes', f"{core_name}_core" ) 

83 setattr( clscls, core_aname, core_function ) 

84 

85 

86def apply_cfc_dynadoc_configuration( 

87 clscls: type[ __.T ], /, 

88 attributes_namer: _nomina.AttributesNamer, 

89 configuration: _nomina.DynadocConfiguration, 

90) -> None: 

91 ''' Stores Dynadoc configuration on metaclass. ''' 

92 configuration_name = attributes_namer( 'classes', 'dynadoc_configuration' ) 

93 setattr( clscls, configuration_name, configuration ) 

94 

95 

96def apply_cfc_constructor( 

97 clscls: type[ __.T ], /, 

98 attributes_namer: _nomina.AttributesNamer, 

99 error_class_provider: _nomina.ErrorClassProvider, 

100) -> None: 

101 ''' Injects '__new__' method into metaclass. ''' 

102 preprocessors = ( 

103 _behaviors.produce_class_construction_preprocessor( 

104 attributes_namer = attributes_namer ), ) 

105 postprocessors = ( 

106 _behaviors.produce_class_construction_postprocessor( 

107 attributes_namer = attributes_namer, 

108 error_class_provider = error_class_provider ), ) 

109 constructor: _nomina.ClassConstructor[ __.T ] = ( 

110 _factories.produce_class_constructor( 

111 attributes_namer = attributes_namer, 

112 preprocessors = preprocessors, 

113 postprocessors = postprocessors ) ) 

114 decorator = produce_class_construction_decorator( 

115 attributes_namer = attributes_namer, constructor = constructor ) 

116 decorator( clscls ) 

117 

118 

119def apply_cfc_initializer( 

120 clscls: type[ __.T ], /, attributes_namer: _nomina.AttributesNamer 

121) -> None: 

122 ''' Injects '__init__' method into metaclass. ''' 

123 completers = ( 

124 _behaviors.produce_class_initialization_completer( 

125 attributes_namer = attributes_namer ), ) 

126 initializer = ( 

127 _factories.produce_class_initializer( 

128 attributes_namer = attributes_namer, 

129 completers = completers ) ) 

130 decorator = produce_class_initialization_decorator( 

131 attributes_namer = attributes_namer, initializer = initializer ) 

132 decorator( clscls ) 

133 

134 

135def apply_cfc_attributes_assigner( 

136 clscls: type[ __.T ], /, 

137 attributes_namer: _nomina.AttributesNamer, 

138 error_class_provider: _nomina.ErrorClassProvider, 

139 implementation_core: __.typx.Optional[ _nomina.AssignerCore ], 

140) -> None: 

141 ''' Injects '__setattr__' method into metaclass. ''' 

142 decorator = produce_attributes_assignment_decorator( 

143 level = 'classes', 

144 attributes_namer = attributes_namer, 

145 error_class_provider = error_class_provider, 

146 implementation_core = implementation_core ) 

147 decorator( clscls ) 

148 

149 

150def apply_cfc_attributes_deleter( 

151 clscls: type[ __.T ], /, 

152 attributes_namer: _nomina.AttributesNamer, 

153 error_class_provider: _nomina.ErrorClassProvider, 

154 implementation_core: __.typx.Optional[ _nomina.DeleterCore ], 

155) -> None: 

156 ''' Injects '__delattr__' method into metaclass. ''' 

157 decorator = produce_attributes_deletion_decorator( 

158 level = 'classes', 

159 attributes_namer = attributes_namer, 

160 error_class_provider = error_class_provider, 

161 implementation_core = implementation_core ) 

162 decorator( clscls ) 

163 

164 

165def apply_cfc_attributes_surveyor( 

166 clscls: type[ __.T ], 

167 attributes_namer: _nomina.AttributesNamer, 

168 implementation_core: __.typx.Optional[ _nomina.SurveyorCore ], 

169) -> None: 

170 ''' Injects '__dir__' method into metaclass. ''' 

171 decorator = produce_attributes_surveillance_decorator( 

172 level = 'classes', 

173 attributes_namer = attributes_namer, 

174 implementation_core = implementation_core ) 

175 decorator( clscls ) 

176 

177 

178def class_factory( # noqa: PLR0913 

179 attributes_namer: _nomina.AttributesNamer = __.calculate_attrname, 

180 error_class_provider: _nomina.ErrorClassProvider = __.provide_error_class, 

181 assigner_core: __.typx.Optional[ _nomina.AssignerCore ] = None, 

182 deleter_core: __.typx.Optional[ _nomina.DeleterCore ] = None, 

183 surveyor_core: __.typx.Optional[ _nomina.SurveyorCore ] = None, 

184 dynadoc_configuration: __.cabc.Mapping[ str, __.typx.Any ] = ( 

185 _dynadoc_configuration ), 

186) -> _nomina.Decorator[ __.T ]: 

187 ''' Produces decorator to apply standard behaviors to metaclass. ''' 

188 def decorate( clscls: type[ __.T ] ) -> type[ __.T ]: 

189 apply_cfc_core_functions( 

190 clscls, 

191 attributes_namer = attributes_namer, 

192 assigner_core = assigner_core, 

193 deleter_core = deleter_core, 

194 surveyor_core = surveyor_core ) 

195 apply_cfc_dynadoc_configuration( 

196 clscls, 

197 attributes_namer = attributes_namer, 

198 configuration = dynadoc_configuration ) 

199 apply_cfc_constructor( 

200 clscls, 

201 attributes_namer = attributes_namer, 

202 error_class_provider = error_class_provider ) 

203 apply_cfc_initializer( clscls, attributes_namer = attributes_namer ) 

204 apply_cfc_attributes_assigner( 

205 clscls, 

206 attributes_namer = attributes_namer, 

207 error_class_provider = error_class_provider, 

208 implementation_core = assigner_core ) 

209 apply_cfc_attributes_deleter( 

210 clscls, 

211 attributes_namer = attributes_namer, 

212 error_class_provider = error_class_provider, 

213 implementation_core = deleter_core ) 

214 apply_cfc_attributes_surveyor( 

215 clscls, 

216 attributes_namer = attributes_namer, 

217 implementation_core = surveyor_core ) 

218 return clscls 

219 

220 return decorate 

221 

222 

223def produce_instances_inception_decorator( # noqa: PLR0913 

224 attributes_namer: _nomina.AttributesNamer, 

225 assigner_core: __.typx.Optional[ _nomina.AssignerCore ], 

226 deleter_core: __.typx.Optional[ _nomina.DeleterCore ], 

227 surveyor_core: __.typx.Optional[ _nomina.SurveyorCore ], 

228 ignore_init_arguments: bool, 

229 mutables: _nomina.BehaviorExclusionVerifiersOmni, 

230 visibles: _nomina.BehaviorExclusionVerifiersOmni, 

231) -> _nomina.Decorator[ __.U ]: 

232 ''' Produces decorator to inject '__new__' or '__init__' method. 

233 

234 Also handles common bookkeeping tasks. 

235 ''' 

236 cores = dict( 

237 instances_assigner_core = assigner_core, 

238 instances_deleter_core = deleter_core, 

239 instances_surveyor_core = surveyor_core ) 

240 cores_default = dict( 

241 assigner = _behaviors.assign_attribute_if_mutable, 

242 deleter = _behaviors.delete_attribute_if_mutable, 

243 surveyor = _behaviors.survey_visible_attributes ) 

244 

245 def decorate( cls: type[ __.U ] ) -> type[ __.U ]: 

246 for core_name in ( 'assigner', 'deleter', 'surveyor' ): 

247 core_function = _behaviors.access_core_function( 

248 cls, 

249 attributes_namer = attributes_namer, 

250 arguments = cores, 

251 level = 'instances', name = core_name, 

252 default = cores_default[ core_name ] ) 

253 core_aname = attributes_namer( 'instances', f"{core_name}_core" ) 

254 setattr( cls, core_aname, core_function ) 

255 behaviors: set[ str ] = set( ) 

256 _behaviors.record_behavior( 

257 cls, attributes_namer = attributes_namer, 

258 level = 'instances', basename = 'mutables', 

259 label = _nomina.immutability_label, behaviors = behaviors, 

260 verifiers = mutables ) 

261 _behaviors.record_behavior( 

262 cls, attributes_namer = attributes_namer, 

263 level = 'instances', basename = 'visibles', 

264 label = _nomina.concealment_label, behaviors = behaviors, 

265 verifiers = visibles ) 

266 decorator = produce_instances_initialization_decorator( 

267 attributes_namer = attributes_namer, 

268 behaviors = behaviors, 

269 ignore_init_arguments = ignore_init_arguments ) 

270 return decorator( cls ) 

271 

272 return decorate 

273 

274 

275# def produce_instances_construction_decorator( 

276# attributes_namer: _nomina.AttributesNamer, 

277# behaviors: __.cabc.MutableSet[ str ], 

278# ) -> _nomina.Decorator[ __.U ]: 

279# ''' Produces decorator to inject '__new__' method. ''' 

280# def decorate( cls_: type[ __.U ] ) -> type[ __.U ]: 

281# behaviors_name = attributes_namer( 'instance', 'behaviors' ) 

282# original = cls_.__dict__.get( '__new__' ) 

283# 

284# if original is None: 

285# 

286# def initialize_with_super( 

287# cls: type[ __.U ], 

288# *posargs: __.typx.Any, 

289# **nomargs: __.typx.Any, 

290# ) -> __.U: 

291# self = super( cls_, cls ).__new__( cls, *posargs, **nomargs ) 

292# _activate_instance_behaviors( 

293# cls_, self, behaviors_name, behaviors ) 

294# return self 

295# 

296# cls_.__new__ = initialize_with_super 

297# 

298# else: 

299# 

300# @__.funct.wraps( original ) 

301# def initialize_with_original( 

302# cls: type[ __.U ], 

303# *posargs: __.typx.Any, 

304# **nomargs: __.typx.Any, 

305# ) -> __.U: 

306# self = original( cls, *posargs, **nomargs ) 

307# _activate_instance_behaviors( 

308# cls_, self, behaviors_name, behaviors ) 

309# return self 

310# 

311# cls_.__new__ = initialize_with_original 

312# 

313# return cls_ 

314# 

315# return decorate 

316 

317 

318def produce_instances_initialization_decorator( 

319 attributes_namer: _nomina.AttributesNamer, 

320 behaviors: __.cabc.MutableSet[ str ], 

321 ignore_init_arguments: bool, 

322) -> _nomina.Decorator[ __.U ]: 

323 ''' Produces decorator to inject '__init__' method into class. ''' 

324 def decorate( cls: type[ __.U ] ) -> type[ __.U ]: 

325 behaviors_name = attributes_namer( 'instance', 'behaviors' ) 

326 original = cls.__dict__.get( '__init__' ) 

327 

328 if original is None: 

329 

330 def initialize_with_super( 

331 self: object, *posargs: __.typx.Any, **nomargs: __.typx.Any 

332 ) -> None: 

333 if ignore_init_arguments: super( cls, self ).__init__( ) 

334 else: super( cls, self ).__init__( *posargs, **nomargs ) 

335 _activate_instance_behaviors( 

336 cls, self, behaviors_name, behaviors ) 

337 

338 cls.__init__ = initialize_with_super 

339 

340 else: 

341 

342 @__.funct.wraps( original ) 

343 def initialize_with_original( 

344 self: object, *posargs: __.typx.Any, **nomargs: __.typx.Any 

345 ) -> None: 

346 if ignore_init_arguments: original( self ) 

347 else: original( self, *posargs, **nomargs ) 

348 _activate_instance_behaviors( 

349 cls, self, behaviors_name, behaviors ) 

350 

351 cls.__init__ = initialize_with_original 

352 

353 return cls 

354 

355 return decorate 

356 

357 

358def produce_attributes_assignment_decorator( 

359 level: str, 

360 attributes_namer: _nomina.AttributesNamer, 

361 error_class_provider: _nomina.ErrorClassProvider, 

362 implementation_core: __.typx.Optional[ _nomina.AssignerCore ], 

363) -> _nomina.Decorator[ __.U ]: 

364 ''' Produces decorator to inject '__setattr__' method into class. ''' 

365 def decorate( cls: type[ __.U ] ) -> type[ __.U ]: 

366 leveli = 'class' if level == 'classes' else level 

367 original = cls.__dict__.get( '__setattr__' ) 

368 core = _behaviors.access_core_function( 

369 cls, 

370 attributes_namer = attributes_namer, 

371 arguments = { f"{level}_assigner": implementation_core }, 

372 level = level, name = 'assigner', 

373 default = _behaviors.assign_attribute_if_mutable ) 

374 

375 if original is None: 

376 

377 def assign_with_super( 

378 self: object, name: str, value: __.typx.Any 

379 ) -> None: 

380 ligation = super( cls, self ).__setattr__ 

381 # Only enforce behaviors at start of MRO. 

382 if cls is not type( self ): 

383 ligation( name, value ) 

384 return 

385 core( 

386 self, 

387 ligation = ligation, 

388 attributes_namer = attributes_namer, 

389 error_class_provider = error_class_provider, 

390 level = leveli, 

391 name = name, value = value ) 

392 

393 cls.__setattr__ = assign_with_super 

394 

395 else: 

396 

397 @__.funct.wraps( original ) 

398 def assign_with_original( 

399 self: object, name: str, value: __.typx.Any 

400 ) -> None: 

401 ligation = __.funct.partial( original, self ) 

402 # Only enforce behaviors at start of MRO. 

403 if cls is not type( self ): 

404 ligation( name, value ) 

405 return 

406 core( 

407 self, 

408 ligation = ligation, 

409 attributes_namer = attributes_namer, 

410 error_class_provider = error_class_provider, 

411 level = leveli, 

412 name = name, value = value ) 

413 

414 cls.__setattr__ = assign_with_original 

415 

416 return cls 

417 

418 return decorate 

419 

420 

421def produce_attributes_deletion_decorator( 

422 level: str, 

423 attributes_namer: _nomina.AttributesNamer, 

424 error_class_provider: _nomina.ErrorClassProvider, 

425 implementation_core: __.typx.Optional[ _nomina.DeleterCore ], 

426) -> _nomina.Decorator[ __.U ]: 

427 ''' Produces decorator to inject '__delattr__' method into class. ''' 

428 def decorate( cls: type[ __.U ] ) -> type[ __.U ]: 

429 leveli = 'class' if level == 'classes' else level 

430 original = cls.__dict__.get( '__delattr__' ) 

431 core = _behaviors.access_core_function( 

432 cls, 

433 attributes_namer = attributes_namer, 

434 arguments = { f"{level}_deleter": implementation_core }, 

435 level = level, name = 'deleter', 

436 default = _behaviors.delete_attribute_if_mutable ) 

437 

438 if original is None: 

439 

440 def delete_with_super( self: object, name: str ) -> None: 

441 ligation = super( cls, self ).__delattr__ 

442 # Only enforce behaviors at start of MRO. 

443 if cls is not type( self ): 

444 ligation( name ) 

445 return 

446 core( 

447 self, 

448 ligation = ligation, 

449 attributes_namer = attributes_namer, 

450 error_class_provider = error_class_provider, 

451 level = leveli, 

452 name = name ) 

453 

454 cls.__delattr__ = delete_with_super 

455 

456 else: 

457 

458 @__.funct.wraps( original ) 

459 def delete_with_original( self: object, name: str ) -> None: 

460 ligation = __.funct.partial( original, self ) 

461 # Only enforce behaviors at start of MRO. 

462 if cls is not type( self ): 

463 ligation( name ) 

464 return 

465 core( 

466 self, 

467 ligation = ligation, 

468 attributes_namer = attributes_namer, 

469 error_class_provider = error_class_provider, 

470 level = leveli, 

471 name = name ) 

472 

473 cls.__delattr__ = delete_with_original 

474 

475 return cls 

476 

477 return decorate 

478 

479 

480def produce_attributes_surveillance_decorator( 

481 level: str, 

482 attributes_namer: _nomina.AttributesNamer, 

483 implementation_core: __.typx.Optional[ _nomina.SurveyorCore ], 

484) -> _nomina.Decorator[ __.U ]: 

485 ''' Produces decorator to inject '__dir__' method into class. ''' 

486 def decorate( cls: type[ __.U ] ) -> type[ __.U ]: 

487 leveli = 'class' if level == 'classes' else level 

488 original = cls.__dict__.get( '__dir__' ) 

489 core = _behaviors.access_core_function( 

490 cls, 

491 attributes_namer = attributes_namer, 

492 arguments = { f"{level}_surveyor": implementation_core }, 

493 level = level, name = 'surveyor', 

494 default = _behaviors.survey_visible_attributes ) 

495 

496 if original is None: 

497 

498 def survey_with_super( 

499 self: object 

500 ) -> __.cabc.Iterable[ str ]: 

501 ligation = super( cls, self ).__dir__ 

502 # Only enforce behaviors at start of MRO. 

503 if cls is not type( self ): return ligation( ) 

504 return core( 

505 self, 

506 ligation = ligation, 

507 attributes_namer = attributes_namer, 

508 level = leveli ) 

509 

510 cls.__dir__ = survey_with_super 

511 

512 else: 

513 

514 @__.funct.wraps( original ) 

515 def survey_with_original( 

516 self: object 

517 ) -> __.cabc.Iterable[ str ]: 

518 ligation = __.funct.partial( original, self ) 

519 # Only enforce behaviors at start of MRO. 

520 if cls is not type( self ): return ligation( ) 

521 return core( 

522 self, 

523 ligation = ligation, 

524 attributes_namer = attributes_namer, 

525 level = leveli ) 

526 

527 cls.__dir__ = survey_with_original 

528 

529 return cls 

530 

531 return decorate 

532 

533 

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

535def dataclass_with_standard_behaviors( # noqa: PLR0913 

536 attributes_namer: _nomina.AttributesNamer = __.calculate_attrname, 

537 error_class_provider: _nomina.ErrorClassProvider = __.provide_error_class, 

538 decorators: _nomina.Decorators[ __.U ] = ( ), 

539 assigner_core: __.typx.Optional[ _nomina.AssignerCore ] = None, 

540 deleter_core: __.typx.Optional[ _nomina.DeleterCore ] = None, 

541 surveyor_core: __.typx.Optional[ _nomina.SurveyorCore ] = None, 

542 ignore_init_arguments: bool = False, 

543 mutables: _nomina.BehaviorExclusionVerifiersOmni = __.mutables_default, 

544 visibles: _nomina.BehaviorExclusionVerifiersOmni = __.visibles_default, 

545) -> _nomina.Decorator[ __.U ]: 

546 # https://github.com/microsoft/pyright/discussions/10344 

547 ''' Dataclass decorator factory. ''' 

548 decorators_: _nomina.Decorators[ __.U ] = ( 

549 _produce_instances_decorators( 

550 attributes_namer = attributes_namer, 

551 error_class_provider = error_class_provider, 

552 assigner_core = assigner_core, 

553 deleter_core = deleter_core, 

554 surveyor_core = surveyor_core, 

555 ignore_init_arguments = ignore_init_arguments, 

556 mutables = mutables, 

557 visibles = visibles ) ) 

558 preparers: _nomina.DecorationPreparers[ __.U ] = ( 

559 _produce_instances_decoration_preparers( 

560 attributes_namer = attributes_namer, 

561 error_class_provider = error_class_provider, 

562 class_preparer = prepare_dataclass_for_instances ) ) 

563 return decoration_by( 

564 *decorators, _dataclass_core, *decorators_, preparers = preparers ) 

565 

566 

567def with_standard_behaviors( # noqa: PLR0913 

568 attributes_namer: _nomina.AttributesNamer = __.calculate_attrname, 

569 error_class_provider: _nomina.ErrorClassProvider = __.provide_error_class, 

570 decorators: _nomina.Decorators[ __.U ] = ( ), 

571 assigner_core: __.typx.Optional[ _nomina.AssignerCore ] = None, 

572 deleter_core: __.typx.Optional[ _nomina.DeleterCore ] = None, 

573 surveyor_core: __.typx.Optional[ _nomina.SurveyorCore ] = None, 

574 ignore_init_arguments: bool = False, 

575 mutables: _nomina.BehaviorExclusionVerifiersOmni = __.mutables_default, 

576 visibles: _nomina.BehaviorExclusionVerifiersOmni = __.visibles_default, 

577) -> _nomina.Decorator[ __.U ]: 

578 ''' Class decorator factory. ''' 

579 decorators_: _nomina.Decorators[ __.U ] = ( 

580 _produce_instances_decorators( 

581 attributes_namer = attributes_namer, 

582 error_class_provider = error_class_provider, 

583 assigner_core = assigner_core, 

584 deleter_core = deleter_core, 

585 surveyor_core = surveyor_core, 

586 ignore_init_arguments = ignore_init_arguments, 

587 mutables = mutables, 

588 visibles = visibles ) ) 

589 preparers: _nomina.DecorationPreparers[ __.U ] = ( 

590 _produce_instances_decoration_preparers( 

591 attributes_namer = attributes_namer, 

592 error_class_provider = error_class_provider ) ) 

593 return decoration_by( *decorators, *decorators_, preparers = preparers ) 

594 

595 

596def _activate_instance_behaviors( 

597 cls: type[ __.U ], 

598 self: object, 

599 behaviors_name: str, 

600 behaviors: __.cabc.MutableSet[ str ], 

601) -> None: 

602 # Only record behaviors at start of MRO. 

603 if cls is not type( self ): return 

604 behaviors_: set[ str ] = ( 

605 _utilities.getattr0( self, behaviors_name, set( ) ) ) 

606 behaviors_.update( behaviors ) 

607 _utilities.setattr0( self, behaviors_name, frozenset( behaviors_ ) ) 

608 

609 

610def _produce_instances_decoration_preparers( 

611 attributes_namer: _nomina.AttributesNamer, 

612 error_class_provider: _nomina.ErrorClassProvider, 

613 class_preparer: __.typx.Optional[ _nomina.ClassPreparer ] = None, 

614) -> _nomina.DecorationPreparers[ __.U ]: 

615 ''' Produces processors for standard decorators. ''' 

616 preprocessors: list[ _nomina.DecorationPreparer[ __.U ] ] = [ ] 

617 if class_preparer is not None: 

618 preprocessors.append( 

619 __.funct.partial( 

620 class_preparer, attributes_namer = attributes_namer ) ) 

621 return tuple( preprocessors ) 

622 

623 

624def _produce_instances_decorators( # noqa: PLR0913 

625 attributes_namer: _nomina.AttributesNamer, 

626 error_class_provider: _nomina.ErrorClassProvider, 

627 assigner_core: __.typx.Optional[ _nomina.AssignerCore ], 

628 deleter_core: __.typx.Optional[ _nomina.DeleterCore ], 

629 surveyor_core: __.typx.Optional[ _nomina.SurveyorCore ], 

630 ignore_init_arguments: bool, 

631 mutables: _nomina.BehaviorExclusionVerifiersOmni, 

632 visibles: _nomina.BehaviorExclusionVerifiersOmni, 

633) -> _nomina.Decorators[ __.U ]: 

634 ''' Produces standard decorators. ''' 

635 decorators: list[ _nomina.Decorator[ __.U ] ] = [ ] 

636 decorators.append( 

637 produce_instances_inception_decorator( 

638 attributes_namer = attributes_namer, 

639 assigner_core = assigner_core, 

640 deleter_core = deleter_core, 

641 surveyor_core = surveyor_core, 

642 ignore_init_arguments = ignore_init_arguments, 

643 mutables = mutables, visibles = visibles ) ) 

644 decorators.append( 

645 produce_attributes_assignment_decorator( 

646 level = 'instances', 

647 attributes_namer = attributes_namer, 

648 error_class_provider = error_class_provider, 

649 implementation_core = assigner_core ) ) 

650 decorators.append( 

651 produce_attributes_deletion_decorator( 

652 level = 'instances', 

653 attributes_namer = attributes_namer, 

654 error_class_provider = error_class_provider, 

655 implementation_core = deleter_core ) ) 

656 decorators.append( 

657 produce_attributes_surveillance_decorator( 

658 level = 'instances', 

659 attributes_namer = attributes_namer, 

660 implementation_core = surveyor_core ) ) 

661 return decorators