corelay.tracker

Includes MetaTracker to track definition order of class attributes.

Classes

MetaTracker

Meta class to track attributes of some type in order of declaration

PublicOrderedDict

Supplies public function to return copy with only keys that are not inclosed in double underscores

Tracker

Tracks all class attributes not enclosed with double underscores in order, and makes them available as its __tracked__ attribute using MetaTracker.

class corelay.tracker.MetaTracker(classname, bases, class_dict)[source]

Bases: ABCMeta

Meta class to track attributes of some type in order of declaration

Example

>>> class OrderedInts(metaclass=MetaTracker):
...     a = 14
...     b = 21
...     c = 42
... OrderedInts(a=0).__tracked__
OrderedDict([('__module__', '__main__'), ('__qualname__', 'OrderedInts'), ('a', 0), ('b', 21), ('c', 42)])

Note

See PEP3115

class corelay.tracker.PublicOrderedDict[source]

Bases: OrderedDict

Supplies public function to return copy with only keys that are not inclosed in double underscores

public()[source]

Returns copy with only keys that are not inclosed in double underscores

class corelay.tracker.Tracker[source]

Bases: object

Tracks all class attributes not enclosed with double underscores in order, and makes them available as its __tracked__ attribute using MetaTracker.

classmethod collect(dtype)[source]

Return all tracked class attributes of a certain type.

Parameters

dtype (type or tuple of type) – Type(s) of the class attributes to collect.

Returns

An OrderedDict, with the attribute names as keys and their corresponding values.

Return type

OrderedDict

collect_attr(dtype)[source]

Return all instance attributes, corresponding to tracked class attributes of a certain type.

Parameters

dtype (type or tuple of type) – Type(s) of the class attributes to collect.

Returns

An OrderedDict, with the attribute names as keys and the corresponding instance attribute values.

Return type

OrderedDict