operator
¶
Concrete operator implementations for lazy evaluation expressions.
This module defines the specific operator classes that implement the LazyOperator abstract base class. Each class represents a mathematical operation like addition, subtraction, multiplication, etc., and provides the implementation for evaluating that operation when all required values are available.
Classes:
Name | Description |
---|---|
Abs |
A lazy operator for absolute value. |
Add |
A lazy operator for addition operations. |
FloorDiv |
A lazy operator for floor division. |
Mod |
A lazy operator for modulo. |
Mul |
A lazy operator for multiplication. |
Neg |
A lazy operator for negation. |
Pos |
A lazy operator for positive. |
Pow |
A lazy operator for exponentiation. |
Sub |
A lazy operator for subtraction. |
TrueDiv |
A lazy operator for true division. |
Abs
dataclass
¶
Abs(*, left: Any = None, right: Any = None)
Bases: LazyOperator
A lazy operator for absolute value.
Methods:
Name | Description |
---|---|
eval |
Evaluate the lazy value with the given values. |
keys |
Get the set of symbol names required to evaluate this operator. |
partial |
Evaluate this operator with the given values. |
ready |
Check if the lazy value is ready to be evaluated. |
eval
¶
eval(**values: Any) -> Any
Evaluate the lazy value with the given values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**values
|
Any
|
Values to be used for evaluation. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The evaluated value. |
Raises:
Type | Description |
---|---|
ValueError
|
If the lazy value is not ready to be evaluated. |
keys
¶
keys() -> set[str]
Get the set of symbol names required to evaluate this operator.
This method collects the required symbol names from both operands (if they are LazyValues) and returns their union.
Returns:
Type | Description |
---|---|
set[str]
|
A set of strings representing all symbol names required to |
set[str]
|
fully evaluate this operator |
partial
¶
partial(**values: Any) -> Any
Evaluate this operator with the given values.
This method recursively evaluates the operands (which may themselves be LazyValues) with the provided values, then applies the operator's specific operation to the results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**values
|
Any
|
Dictionary mapping symbol names to their values |
{}
|
Returns:
Type | Description |
---|---|
Any
|
The result of applying the operation to the partially evaluated operands, |
Any
|
which may be a concrete value or another LazyValue if some symbols |
Any
|
remain unevaluated |
ready
¶
ready() -> bool
Check if the lazy value is ready to be evaluated.
A lazy value is considered ready for evaluation when it doesn't require any additional values to be provided. This is determined by checking if the set of required keys is empty.
Returns:
Type | Description |
---|---|
bool
|
True if the lazy value can be evaluated without additional values, |
bool
|
False otherwise |
Add
dataclass
¶
Add(*, left: Any = None, right: Any = None)
Bases: LazyOperator
A lazy operator for addition operations.
This class implements the addition operation for lazy evaluation expressions. It evaluates to the sum of its left and right operands when all required values are available.
Example
# Create an expression that adds width and height
from .schema import Symbol
width = Symbol("width")
height = Symbol("height")
expr = Add(left=width, right=height)
# Evaluate the expression with specific values
result = expr.eval(width=1280, height=720) # Returns 2000
Methods:
Name | Description |
---|---|
eval |
Evaluate the lazy value with the given values. |
keys |
Get the set of symbol names required to evaluate this operator. |
partial |
Evaluate this operator with the given values. |
ready |
Check if the lazy value is ready to be evaluated. |
eval
¶
eval(**values: Any) -> Any
Evaluate the lazy value with the given values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**values
|
Any
|
Values to be used for evaluation. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The evaluated value. |
Raises:
Type | Description |
---|---|
ValueError
|
If the lazy value is not ready to be evaluated. |
keys
¶
keys() -> set[str]
Get the set of symbol names required to evaluate this operator.
This method collects the required symbol names from both operands (if they are LazyValues) and returns their union.
Returns:
Type | Description |
---|---|
set[str]
|
A set of strings representing all symbol names required to |
set[str]
|
fully evaluate this operator |
partial
¶
partial(**values: Any) -> Any
Evaluate this operator with the given values.
This method recursively evaluates the operands (which may themselves be LazyValues) with the provided values, then applies the operator's specific operation to the results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**values
|
Any
|
Dictionary mapping symbol names to their values |
{}
|
Returns:
Type | Description |
---|---|
Any
|
The result of applying the operation to the partially evaluated operands, |
Any
|
which may be a concrete value or another LazyValue if some symbols |
Any
|
remain unevaluated |
ready
¶
ready() -> bool
Check if the lazy value is ready to be evaluated.
A lazy value is considered ready for evaluation when it doesn't require any additional values to be provided. This is determined by checking if the set of required keys is empty.
Returns:
Type | Description |
---|---|
bool
|
True if the lazy value can be evaluated without additional values, |
bool
|
False otherwise |
FloorDiv
dataclass
¶
FloorDiv(*, left: Any = None, right: Any = None)
Bases: LazyOperator
A lazy operator for floor division.
Methods:
Name | Description |
---|---|
eval |
Evaluate the lazy value with the given values. |
keys |
Get the set of symbol names required to evaluate this operator. |
partial |
Evaluate this operator with the given values. |
ready |
Check if the lazy value is ready to be evaluated. |
eval
¶
eval(**values: Any) -> Any
Evaluate the lazy value with the given values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**values
|
Any
|
Values to be used for evaluation. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The evaluated value. |
Raises:
Type | Description |
---|---|
ValueError
|
If the lazy value is not ready to be evaluated. |
keys
¶
keys() -> set[str]
Get the set of symbol names required to evaluate this operator.
This method collects the required symbol names from both operands (if they are LazyValues) and returns their union.
Returns:
Type | Description |
---|---|
set[str]
|
A set of strings representing all symbol names required to |
set[str]
|
fully evaluate this operator |
partial
¶
partial(**values: Any) -> Any
Evaluate this operator with the given values.
This method recursively evaluates the operands (which may themselves be LazyValues) with the provided values, then applies the operator's specific operation to the results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**values
|
Any
|
Dictionary mapping symbol names to their values |
{}
|
Returns:
Type | Description |
---|---|
Any
|
The result of applying the operation to the partially evaluated operands, |
Any
|
which may be a concrete value or another LazyValue if some symbols |
Any
|
remain unevaluated |
ready
¶
ready() -> bool
Check if the lazy value is ready to be evaluated.
A lazy value is considered ready for evaluation when it doesn't require any additional values to be provided. This is determined by checking if the set of required keys is empty.
Returns:
Type | Description |
---|---|
bool
|
True if the lazy value can be evaluated without additional values, |
bool
|
False otherwise |
Mod
dataclass
¶
Mod(*, left: Any = None, right: Any = None)
Bases: LazyOperator
A lazy operator for modulo.
Methods:
Name | Description |
---|---|
eval |
Evaluate the lazy value with the given values. |
keys |
Get the set of symbol names required to evaluate this operator. |
partial |
Evaluate this operator with the given values. |
ready |
Check if the lazy value is ready to be evaluated. |
eval
¶
eval(**values: Any) -> Any
Evaluate the lazy value with the given values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**values
|
Any
|
Values to be used for evaluation. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The evaluated value. |
Raises:
Type | Description |
---|---|
ValueError
|
If the lazy value is not ready to be evaluated. |
keys
¶
keys() -> set[str]
Get the set of symbol names required to evaluate this operator.
This method collects the required symbol names from both operands (if they are LazyValues) and returns their union.
Returns:
Type | Description |
---|---|
set[str]
|
A set of strings representing all symbol names required to |
set[str]
|
fully evaluate this operator |
partial
¶
partial(**values: Any) -> Any
Evaluate this operator with the given values.
This method recursively evaluates the operands (which may themselves be LazyValues) with the provided values, then applies the operator's specific operation to the results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**values
|
Any
|
Dictionary mapping symbol names to their values |
{}
|
Returns:
Type | Description |
---|---|
Any
|
The result of applying the operation to the partially evaluated operands, |
Any
|
which may be a concrete value or another LazyValue if some symbols |
Any
|
remain unevaluated |
ready
¶
ready() -> bool
Check if the lazy value is ready to be evaluated.
A lazy value is considered ready for evaluation when it doesn't require any additional values to be provided. This is determined by checking if the set of required keys is empty.
Returns:
Type | Description |
---|---|
bool
|
True if the lazy value can be evaluated without additional values, |
bool
|
False otherwise |
Mul
dataclass
¶
Mul(*, left: Any = None, right: Any = None)
Bases: LazyOperator
A lazy operator for multiplication.
Methods:
Name | Description |
---|---|
eval |
Evaluate the lazy value with the given values. |
keys |
Get the set of symbol names required to evaluate this operator. |
partial |
Evaluate this operator with the given values. |
ready |
Check if the lazy value is ready to be evaluated. |
eval
¶
eval(**values: Any) -> Any
Evaluate the lazy value with the given values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**values
|
Any
|
Values to be used for evaluation. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The evaluated value. |
Raises:
Type | Description |
---|---|
ValueError
|
If the lazy value is not ready to be evaluated. |
keys
¶
keys() -> set[str]
Get the set of symbol names required to evaluate this operator.
This method collects the required symbol names from both operands (if they are LazyValues) and returns their union.
Returns:
Type | Description |
---|---|
set[str]
|
A set of strings representing all symbol names required to |
set[str]
|
fully evaluate this operator |
partial
¶
partial(**values: Any) -> Any
Evaluate this operator with the given values.
This method recursively evaluates the operands (which may themselves be LazyValues) with the provided values, then applies the operator's specific operation to the results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**values
|
Any
|
Dictionary mapping symbol names to their values |
{}
|
Returns:
Type | Description |
---|---|
Any
|
The result of applying the operation to the partially evaluated operands, |
Any
|
which may be a concrete value or another LazyValue if some symbols |
Any
|
remain unevaluated |
ready
¶
ready() -> bool
Check if the lazy value is ready to be evaluated.
A lazy value is considered ready for evaluation when it doesn't require any additional values to be provided. This is determined by checking if the set of required keys is empty.
Returns:
Type | Description |
---|---|
bool
|
True if the lazy value can be evaluated without additional values, |
bool
|
False otherwise |
Neg
dataclass
¶
Neg(*, left: Any = None, right: Any = None)
Bases: LazyOperator
A lazy operator for negation.
Methods:
Name | Description |
---|---|
eval |
Evaluate the lazy value with the given values. |
keys |
Get the set of symbol names required to evaluate this operator. |
partial |
Evaluate this operator with the given values. |
ready |
Check if the lazy value is ready to be evaluated. |
eval
¶
eval(**values: Any) -> Any
Evaluate the lazy value with the given values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**values
|
Any
|
Values to be used for evaluation. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The evaluated value. |
Raises:
Type | Description |
---|---|
ValueError
|
If the lazy value is not ready to be evaluated. |
keys
¶
keys() -> set[str]
Get the set of symbol names required to evaluate this operator.
This method collects the required symbol names from both operands (if they are LazyValues) and returns their union.
Returns:
Type | Description |
---|---|
set[str]
|
A set of strings representing all symbol names required to |
set[str]
|
fully evaluate this operator |
partial
¶
partial(**values: Any) -> Any
Evaluate this operator with the given values.
This method recursively evaluates the operands (which may themselves be LazyValues) with the provided values, then applies the operator's specific operation to the results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**values
|
Any
|
Dictionary mapping symbol names to their values |
{}
|
Returns:
Type | Description |
---|---|
Any
|
The result of applying the operation to the partially evaluated operands, |
Any
|
which may be a concrete value or another LazyValue if some symbols |
Any
|
remain unevaluated |
ready
¶
ready() -> bool
Check if the lazy value is ready to be evaluated.
A lazy value is considered ready for evaluation when it doesn't require any additional values to be provided. This is determined by checking if the set of required keys is empty.
Returns:
Type | Description |
---|---|
bool
|
True if the lazy value can be evaluated without additional values, |
bool
|
False otherwise |
Pos
dataclass
¶
Pos(*, left: Any = None, right: Any = None)
Bases: LazyOperator
A lazy operator for positive.
Methods:
Name | Description |
---|---|
eval |
Evaluate the lazy value with the given values. |
keys |
Get the set of symbol names required to evaluate this operator. |
partial |
Evaluate this operator with the given values. |
ready |
Check if the lazy value is ready to be evaluated. |
eval
¶
eval(**values: Any) -> Any
Evaluate the lazy value with the given values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**values
|
Any
|
Values to be used for evaluation. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The evaluated value. |
Raises:
Type | Description |
---|---|
ValueError
|
If the lazy value is not ready to be evaluated. |
keys
¶
keys() -> set[str]
Get the set of symbol names required to evaluate this operator.
This method collects the required symbol names from both operands (if they are LazyValues) and returns their union.
Returns:
Type | Description |
---|---|
set[str]
|
A set of strings representing all symbol names required to |
set[str]
|
fully evaluate this operator |
partial
¶
partial(**values: Any) -> Any
Evaluate this operator with the given values.
This method recursively evaluates the operands (which may themselves be LazyValues) with the provided values, then applies the operator's specific operation to the results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**values
|
Any
|
Dictionary mapping symbol names to their values |
{}
|
Returns:
Type | Description |
---|---|
Any
|
The result of applying the operation to the partially evaluated operands, |
Any
|
which may be a concrete value or another LazyValue if some symbols |
Any
|
remain unevaluated |
ready
¶
ready() -> bool
Check if the lazy value is ready to be evaluated.
A lazy value is considered ready for evaluation when it doesn't require any additional values to be provided. This is determined by checking if the set of required keys is empty.
Returns:
Type | Description |
---|---|
bool
|
True if the lazy value can be evaluated without additional values, |
bool
|
False otherwise |
Pow
dataclass
¶
Pow(*, left: Any = None, right: Any = None)
Bases: LazyOperator
A lazy operator for exponentiation.
Methods:
Name | Description |
---|---|
eval |
Evaluate the lazy value with the given values. |
keys |
Get the set of symbol names required to evaluate this operator. |
partial |
Evaluate this operator with the given values. |
ready |
Check if the lazy value is ready to be evaluated. |
eval
¶
eval(**values: Any) -> Any
Evaluate the lazy value with the given values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**values
|
Any
|
Values to be used for evaluation. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The evaluated value. |
Raises:
Type | Description |
---|---|
ValueError
|
If the lazy value is not ready to be evaluated. |
keys
¶
keys() -> set[str]
Get the set of symbol names required to evaluate this operator.
This method collects the required symbol names from both operands (if they are LazyValues) and returns their union.
Returns:
Type | Description |
---|---|
set[str]
|
A set of strings representing all symbol names required to |
set[str]
|
fully evaluate this operator |
partial
¶
partial(**values: Any) -> Any
Evaluate this operator with the given values.
This method recursively evaluates the operands (which may themselves be LazyValues) with the provided values, then applies the operator's specific operation to the results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**values
|
Any
|
Dictionary mapping symbol names to their values |
{}
|
Returns:
Type | Description |
---|---|
Any
|
The result of applying the operation to the partially evaluated operands, |
Any
|
which may be a concrete value or another LazyValue if some symbols |
Any
|
remain unevaluated |
ready
¶
ready() -> bool
Check if the lazy value is ready to be evaluated.
A lazy value is considered ready for evaluation when it doesn't require any additional values to be provided. This is determined by checking if the set of required keys is empty.
Returns:
Type | Description |
---|---|
bool
|
True if the lazy value can be evaluated without additional values, |
bool
|
False otherwise |
Sub
dataclass
¶
Sub(*, left: Any = None, right: Any = None)
Bases: LazyOperator
A lazy operator for subtraction.
Methods:
Name | Description |
---|---|
eval |
Evaluate the lazy value with the given values. |
keys |
Get the set of symbol names required to evaluate this operator. |
partial |
Evaluate this operator with the given values. |
ready |
Check if the lazy value is ready to be evaluated. |
eval
¶
eval(**values: Any) -> Any
Evaluate the lazy value with the given values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**values
|
Any
|
Values to be used for evaluation. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The evaluated value. |
Raises:
Type | Description |
---|---|
ValueError
|
If the lazy value is not ready to be evaluated. |
keys
¶
keys() -> set[str]
Get the set of symbol names required to evaluate this operator.
This method collects the required symbol names from both operands (if they are LazyValues) and returns their union.
Returns:
Type | Description |
---|---|
set[str]
|
A set of strings representing all symbol names required to |
set[str]
|
fully evaluate this operator |
partial
¶
partial(**values: Any) -> Any
Evaluate this operator with the given values.
This method recursively evaluates the operands (which may themselves be LazyValues) with the provided values, then applies the operator's specific operation to the results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**values
|
Any
|
Dictionary mapping symbol names to their values |
{}
|
Returns:
Type | Description |
---|---|
Any
|
The result of applying the operation to the partially evaluated operands, |
Any
|
which may be a concrete value or another LazyValue if some symbols |
Any
|
remain unevaluated |
ready
¶
ready() -> bool
Check if the lazy value is ready to be evaluated.
A lazy value is considered ready for evaluation when it doesn't require any additional values to be provided. This is determined by checking if the set of required keys is empty.
Returns:
Type | Description |
---|---|
bool
|
True if the lazy value can be evaluated without additional values, |
bool
|
False otherwise |
TrueDiv
dataclass
¶
TrueDiv(*, left: Any = None, right: Any = None)
Bases: LazyOperator
A lazy operator for true division.
Methods:
Name | Description |
---|---|
eval |
Evaluate the lazy value with the given values. |
keys |
Get the set of symbol names required to evaluate this operator. |
partial |
Evaluate this operator with the given values. |
ready |
Check if the lazy value is ready to be evaluated. |
eval
¶
eval(**values: Any) -> Any
Evaluate the lazy value with the given values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**values
|
Any
|
Values to be used for evaluation. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The evaluated value. |
Raises:
Type | Description |
---|---|
ValueError
|
If the lazy value is not ready to be evaluated. |
keys
¶
keys() -> set[str]
Get the set of symbol names required to evaluate this operator.
This method collects the required symbol names from both operands (if they are LazyValues) and returns their union.
Returns:
Type | Description |
---|---|
set[str]
|
A set of strings representing all symbol names required to |
set[str]
|
fully evaluate this operator |
partial
¶
partial(**values: Any) -> Any
Evaluate this operator with the given values.
This method recursively evaluates the operands (which may themselves be LazyValues) with the provided values, then applies the operator's specific operation to the results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**values
|
Any
|
Dictionary mapping symbol names to their values |
{}
|
Returns:
Type | Description |
---|---|
Any
|
The result of applying the operation to the partially evaluated operands, |
Any
|
which may be a concrete value or another LazyValue if some symbols |
Any
|
remain unevaluated |
ready
¶
ready() -> bool
Check if the lazy value is ready to be evaluated.
A lazy value is considered ready for evaluation when it doesn't require any additional values to be provided. This is determined by checking if the set of required keys is empty.
Returns:
Type | Description |
---|---|
bool
|
True if the lazy value can be evaluated without additional values, |
bool
|
False otherwise |