- class atom.atom.Atom
The base class for defining atom objects.
Atom objects are special Python objects which never allocate an instance dictionary unless one is explicitly requested. The storage for an atom is instead computed from the Member objects declared on the class. Memory is reserved for these members with no over allocation.
This restriction make atom objects a bit less flexible than normal Python objects, but they are between 3x-10x more memory efficient than normal objects depending on the number of attributes.
- classmethod members() Mapping[str, atom.catom.Member]
Get the members dictionary for the type.
result – The dictionary of members defined on the class. User code should not modify the contents of the dict.
- Return type
- suppress_notifications() Iterator[None]
Disable member notifications within in a context.
result – A context manager which disables atom notifications for the duration of the context. When the context exits, the state is restored to its previous value.
- Return type
- class atom.atom.AtomMeta(name: str, bases: Tuple[type, ...], dct: Dict[str, Any], enable_weakrefs: bool = False, use_annotations: bool = True, type_containers: int = 1)
The metaclass for classes derived from Atom.
This metaclass computes the memory layout of the members in a given class so that the CAtom class can allocate exactly enough space for the object data slots when it instantiates an object.
All classes deriving from Atom will be automatically slotted, which will prevent the creation of an instance dictionary and also the ability of an Atom to be weakly referenceable. If that behavior is required, then a subclasss should declare the appropriate slots.
- class atom.atom.ExtendedObserver(funcname: str, attr: str)
A callable object used to implement extended observers.
- attr: str
Attribute name on the target object which should be observed.
- funcname: str
Name of the function on the owner object which should be used as the observer.
- exception atom.atom.MissingMemberWarning
Signal an expected member is not present.
- class atom.atom.ObserveHandler(pairs: List[Tuple[str, Optional[str]]], change_types: atom.catom.ChangeType = ChangeType.ANY)
An object used to temporarily store observe decorator state.
- func: Optional[Callable[[Mapping[str, Any]], None]]
Callable to be used as observer callback.
- funcname: Optional[str]
Name of the callable. Used by the metaclass.
- pairs: List[Tuple[str, Optional[str]]]
List of 2-tuples which stores the pair information for the observers.
- atom.atom.add_member(cls: atom.atom.AtomMeta, name: str, member: atom.catom.Member) None
Add or override a member after the class creation.
- atom.atom.observe(*names: str, change_types: atom.catom.ChangeType = ChangeType.ANY) atom.atom.ObserveHandler
A decorator which can be used to observe members on a class.
*names – The str names of the attributes to observe on the object. These must be of the form ‘foo’ or ‘foo.bar’.
change_types – The flag specifying the type of changes to observe.
- class atom.atom.set_default(value: Any)
An object used to set the default value of a base class member.
- name: Optional[str]
Name of the member for which a new default value should be set. Used by the metaclass.
- value: Any
New default value to be set.