attribtool¶
Author: Jacek Kotlarski –<szumak@virthost.pl> Created: 02.07.2023
Purpose: Provide helpers that restrict adding attributes to classes and instances.
The module collects mixins and metaclasses that prevent accidental creation of new attributes at runtime. Inspired by recipes from Python Cookbook (2004, Martelli et al.).
- class jsktoolbox.attribtool.NoNewAttributes[source]¶
Bases:
objectPrevent instances of subclasses from gaining new attributes.
### Purpose: Blocks dynamic attribute creation by overriding __setattr__ for both instances and the metaclass.
- class jsktoolbox.attribtool.NoDynamicAttributes[source]¶
Bases:
objectMix-in that disallows adding attributes to class instances.
### Purpose: Ensures all attributes must be declared up-front; runtime additions raise AttributeError.
- class jsktoolbox.attribtool.ReadOnlyClass[source]¶
Bases:
typeMetaclass that makes class attributes immutable after definition.
### Purpose: Raises AttributeError whenever class-level attributes are reassigned.
- __setattr__(name, value)[source]¶
Block assignment to class-level attributes.
### Raises: * AttributeError: Always raised to prevent modification.
- __init__(*args, **kwargs)¶
- mro()¶
Return a type’s method resolution order.