pytableaux.logics

registry

registry: Registry

The default built-in registry

Parameters:

key (str | ModuleType) --

Return type:

LogicType

class Registry(*, source=None)[source]

Logic module registry.

packages: qset[str]

Packages containing logic modules to load from.

modules: QsetView[str]

The set of loaded module names.

index: Mapping

Mapping to module.__name__ for each of its keys. See get().

discard(logic)[source]

Discard a logic module.

copy()[source]

Copy the registry.

clear()[source]

Clear the registry.

__call__(key, /)[source]

Get a logic from the registry, importing if needed. See get()

Parameters:

key (str | module) --

Return type:

LogicType

get(ref, default=<object object>, /)[source]

Get a logic from the registry, importing if needed.

Parameters:
  • key --

    One of the following:

    • Full module.__name__

    • local ID (lowercase last part of module.__name__)

    • The module's Meta.name attribute

    • Module object

  • default -- A default value to suppress error.

Returns:

The logic module

Raises:
Return type:

LogicType

locate(ref, default=<object object>, /)[source]

Like get() but also searches the __module__ attribute of classes, methods, and functions to locate the logic in which it was defined.

Parameters:
  • ref -- A key accepted by get(), or a class, method, or function defined in a logic module.

  • default -- A default value to suppress not found error.

Returns:

The logic module

Raises:
Return type:

LogicType

package_all(package, /)[source]

Yield the package's declared logic modules from its __all__ attribute.

Parameters:

package (str | module) --

import_all()[source]

Import all logics for all registry packages. See import_package().

Return type:

None

import_package(package, /)[source]

Import all logic modules for a package. Uses the __all__ attribute to list the logic names.

Raises:

ValueError -- if the package is not in the registry packages.

Parameters:

package (str | module) --

Return type:

None

grouped(keys=None, /, *, sort=True, key=None, reverse=False)[source]

Group logics by category.

Parameters:
  • keys -- Iterable of keys accepted by get().

  • sort -- Whether to sort each group. Default True.

  • key -- The sort key for the groups. Default is logic.Meta.

  • reverse -- Whether to reverse sort each group.

Returns:

A dict from each category name to the list of logic modules.

Raises:

ValueError -- if any not found.

Return type:

dict[Category, list[LogicType]]