API Documentation

Module lockup

Immutable module class and namespace factory.

class lockup.Class(name, bases, namespace)

Bases: type

Produces classes which have immutable attributes.

Non-public attributes of each class are concealed from dir().

Note

Only class attributes are immutable. Instances of immutable classes will have mutable attributes without additional intervention beyond the scope of this package.

mro()

Return a type’s method resolution order.

class lockup.NamespaceClass(name, bases, namespace)

Bases: lockup.Class

Produces namespace classes which have immutable attributes.

Each produced namespace is a unique class, which cannot be instantiated.

Non-public attributes of each class are concealed from dir().

Warning

Although most descriptor attributes will be inert on a class, types.DynamicClassAttribute() and similar, may trigger attribute errors when accessed. However, these are a fairly rare case and are probably not needed on namespaces, in general.

mro()

Return a type’s method resolution order.

lockup.create_namespace(**nomargs)

Creates immutable namespaces from nominative arguments.

class lockup.Module(name, doc=None)

Bases: module

Module whose attributes are immutable except during module definition.

Can replace the __class__ attribute on an existing module.

Non-public attributes of the module are concealed from dir(). Also, a copy of the module dictionary is returned when the __dict__ attribute is accessed; this is done to remove a backdoor by which attributes could be mutated.

Note

Copies of the module dictionary are mutable so as to not violate the internal expectations of Python as well as important packages, such as doctest. Ideally, these would be immutable, but cannot be as of this writing.

lockup.reclassify_module(module)

Assigns Module as class for module.

Takes either a module object or the name of a module in sys.modules. If the module has already been reclassified, then nothing is done (i.e., the operation is idempotent).

Module lockup.exceptions

All exceptions raised by this package have a common base: Exception0.

exception lockup.exceptions.Exception0(*things, tags=None, **sundry)

Bases: BaseException

Base for all exceptions in the package.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception lockup.exceptions.FugitiveException(supplement=None)

Bases: lockup.exceptions.InvalidState, RuntimeError

Alert about fugitive exception intercepted at API boundary.

An fugitive exception is one which is not intended to be reported across the package API boundary. Fugitive exceptions include Python built-ins, such as IndexError.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception lockup.exceptions.ImpermissibleAttributeOperation(*things, tags=None, **sundry)

Bases: lockup.exceptions.ImpermissibleOperation, AttributeError

Complaint about impermissible attribute operation.

Cannot use ImpermissibleOperation because some packages, such as Sphinx Autodoc, expect an AttributeError.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception lockup.exceptions.ImpermissibleOperation(*things, tags=None, **sundry)

Bases: lockup.exceptions.InvalidOperation, TypeError

Complaint about impermissible operation.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception lockup.exceptions.InaccessibleAttribute(*things, tags=None, **sundry)

Bases: lockup.exceptions.InaccessibleEntity, AttributeError

Complaint about attempt to retrieve inaccessible attribute.

Cannot use InaccessibleEntity because some Python internals expect an AttributeError.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception lockup.exceptions.InaccessibleEntity(*things, tags=None, **sundry)

Bases: lockup.exceptions.InvalidOperation

Complaint about attempt to retrieve inaccessible entity.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception lockup.exceptions.IncorrectData(*things, tags=None, **sundry)

Bases: lockup.exceptions.InvalidOperation, TypeError, ValueError

Complaint about incorrect data for invocation or operation.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception lockup.exceptions.InvalidOperation(*things, tags=None, **sundry)

Bases: lockup.exceptions.Exception0, Exception

Complaint about invalid operation.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception lockup.exceptions.InvalidState(supplement=None)

Bases: lockup.exceptions.Exception0, Exception

Alert about invalid internal state in the package.

Owner of problem: maintainers of this package.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.