metadsl.normalized

Normalized expressions, for deduping and single replacements.

Functions

expression_children(expr)

rtype

Iterable[Tuple[Union[int, str], object]]

hash_value(value)

Computes some hash for a value that should be stable.

Classes

Children(args, kwargs)

ExpressionReference(_graph, _optional_index)

This is a data structure that holds onto a graph of expression and has a pointer to one node, to represent it.

Graph(expr)

Graph of all expression

class metadsl.normalized.Children(args, kwargs)[source]
args: Tuple[Hash, ...]
kwargs: Dict[str, Hash]
class metadsl.normalized.ExpressionReference(_graph, _optional_index)[source]

This is a data structure that holds onto a graph of expression and has a pointer to one node, to represent it.

property children: metadsl.normalized.Children

Returns the direct children of this node if it has any.

Return type

Children

property descendents: Iterable[metadsl.normalized.ExpressionReference]

Returns all nodes of this expression reference. If any of them get their expression replaced, it will replace that sub-node of this expression.

If this is the root node, will return them in topo order, otherwise will be arbitrary

Return type

Iterable[ExpressionReference]

property expression: object

Returns the expression this references

Return type

object

classmethod from_expression(expr)[source]

Create a new reference from an expression

Return type

ExpressionReference

property hash: Hash

Returns the Hash of the top level expression

Return type

NewType()(Hash, str)

replace(new_expression)[source]

Replace this expression with a new one

Return type

None

metadsl.normalized.Hash(x)
metadsl.normalized.hash_value(value)[source]

Computes some hash for a value that should be stable. Either use the built in hash, or if we cannot (like the object is mutable) then use the id.

It’s a single dispatch function so that you can register custom hashes for objects you don’t control.

Return type

int