apptools.type_registry.type_registry module

class apptools.type_registry.type_registry.LazyRegistry[source]

Bases: TypeRegistry

A type registry that will lazily import the registered objects.

Register ‘__module__:__name__’ strings for the lazily imported objects. These will only be imported when the matching type is looked up. The module name must be a fully-qualified absolute name with all of the parent packages specified.

lookup_by_type(typ)[source]

Look up the registered object for a type.

class apptools.type_registry.type_registry.TypeRegistry[source]

Bases: object

Register objects for types.

Each type maintains a stack of registered objects that can be pushed and popped.

lookup(instance)[source]

Look up the registered object for the given instance.

Parameters

instance (object) – An instance of a possibly registered type.

Returns

obj – The registered object for the type of the instance, one of the type’s superclasses, or else one of the ABCs the type implements.

Return type

object

Raises

KeyError if the instance's type has not been registered.

lookup_all(instance)[source]

Look up all the registered objects for the given instance.

Parameters

instance (object) – An instance of a possibly registered type.

Returns

objs – The list of registered objects for the instance. If the given instance is not registered, its superclasses are searched. If none of the superclasses are registered, search the possible ABCs.

Return type

list of objects

Raises

KeyError if the instance's type has not been registered.

lookup_all_by_type(typ)[source]

Look up all the registered objects for a type.

Parameters

typ (type) –

Returns

objs – The list of registered objects for the type. If the given type is not registered, its superclasses are searched. If none of the superclasses are registered, search the possible ABCs.

Return type

list of objects

Raises

KeyError if the type has not been registered.

lookup_by_type(typ)[source]

Look up the registered object for a type.

Parameters

typ (type) –

Returns

obj – The registered object for the type, one of its superclasses, or else one of the ABCs it implements.

Return type

object

Raises

KeyError if the type has not been registered.

pop(typ)[source]

Pop a registered object for the given type.

Parameters

typ (type or '__module__:__name__' string for a type) –

Returns

obj – The last registered object for the type.

Return type

object

Raises

KeyError if the type is not registered.

push(typ, obj)[source]

Push an object onto the stack for the given type.

Parameters
  • typ (type or '__module__:__name__' string for a type) –

  • obj (object) – The object to register.

push_abc(typ, obj)[source]

Push an object onto the stack for the given ABC.

Parameters
  • typ (abc.ABCMeta) –

  • obj (object) –

apptools.type_registry.type_registry.get_mro(obj_class)[source]

Get a reasonable method resolution order of a class and its superclasses for both old-style and new-style classes.