Testable#

class discopy.testable.Testable[source]#

Bases: abc.ABC, Generic

A type that comes with a search strategy generating its instances, and the laws every such type obeys: a term reads back from its representation, its pickle and its tree.

abstract classmethod strategy(**params)[source]#

Build a strategy for instances of cls.

An override that delegates to another strategy accepts **params, pops the parameters it consumes and forwards the rest, so that a caller’s bounds pass through unchanged and a subclass overrides what a base popped just by passing it. A terminal strategy instead declares exactly the parameters it implements: a constraint it cannot honour fails loudly as an unexpected keyword rather than being silently dropped.

Return type:

st.SearchStrategy[T]

classmethod environment()[source]#

The namespace the representation of a term reads back in: the public names of the package, as from discopy import * binds them, so that a representation qualified by module such as cat.Box('f', cat.Ob('x'), cat.Ob('y')) evaluates, and then those of the module the category is defined in, so that one printing bare names such as Tensor[int]([0], dom=Dim(1), cod=Dim(1)) evaluates too. The module comes second because a term prints the names its own module binds: Dim in discopy.tensor is the one a tensor is built from.

The import is local because the package imports this module.

Return type:

dict

transparency[source]#

The representation of a term evaluates back to it, in the environment() of its type.

pickling[source]#

the equation is between the pairs of a class and a term, since a subscript of a discopy.utils.NamedGeneric is part of what a pickle keeps.

Type:

A term loads back from its pickle, of the same class

serialisation[source]#

A term decodes back from its tree and from the JSON of its tree. A type without a tree declares the law inapplicable.