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 |
---|---|
Add |
A lazy operator for addition operations. |
Sub |
A lazy operator for subtraction. |
Mul |
A lazy operator for multiplication. |
TrueDiv |
A lazy operator for true division. |
Pow |
A lazy operator for exponentiation. |
Neg |
A lazy operator for negation. |
Pos |
A lazy operator for positive. |
Abs |
A lazy operator for absolute value. |
Mod |
A lazy operator for modulo. |
FloorDiv |
A lazy operator for floor division. |
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. |
partial |
Partially evaluate this operator with the given values. |
ready |
Check if the lazy value is ready to be evaluated. |
keys |
Get the set of symbol names required to evaluate this operator. |
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. |
partial
¶
partial(**values: Any) -> Any
Partially 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 |
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 |
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. |
partial |
Partially evaluate this operator with the given values. |
ready |
Check if the lazy value is ready to be evaluated. |
keys |
Get the set of symbol names required to evaluate this operator. |
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. |
partial
¶
partial(**values: Any) -> Any
Partially 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 |
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 |
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. |
partial |
Partially evaluate this operator with the given values. |
ready |
Check if the lazy value is ready to be evaluated. |
keys |
Get the set of symbol names required to evaluate this operator. |
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. |
partial
¶
partial(**values: Any) -> Any
Partially 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 |
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 |
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. |
partial |
Partially evaluate this operator with the given values. |
ready |
Check if the lazy value is ready to be evaluated. |
keys |
Get the set of symbol names required to evaluate this operator. |
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. |
partial
¶
partial(**values: Any) -> Any
Partially 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 |
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 |
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. |
partial |
Partially evaluate this operator with the given values. |
ready |
Check if the lazy value is ready to be evaluated. |
keys |
Get the set of symbol names required to evaluate this operator. |
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. |
partial
¶
partial(**values: Any) -> Any
Partially 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 |
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 |
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. |
partial |
Partially evaluate this operator with the given values. |
ready |
Check if the lazy value is ready to be evaluated. |
keys |
Get the set of symbol names required to evaluate this operator. |
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. |
partial
¶
partial(**values: Any) -> Any
Partially 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 |
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 |
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. |
partial |
Partially evaluate this operator with the given values. |
ready |
Check if the lazy value is ready to be evaluated. |
keys |
Get the set of symbol names required to evaluate this operator. |
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. |
partial
¶
partial(**values: Any) -> Any
Partially 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 |
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 |
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. |
partial |
Partially evaluate this operator with the given values. |
ready |
Check if the lazy value is ready to be evaluated. |
keys |
Get the set of symbol names required to evaluate this operator. |
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. |
partial
¶
partial(**values: Any) -> Any
Partially 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 |
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 |
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. |
partial |
Partially evaluate this operator with the given values. |
ready |
Check if the lazy value is ready to be evaluated. |
keys |
Get the set of symbol names required to evaluate this operator. |
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. |
partial
¶
partial(**values: Any) -> Any
Partially 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 |
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 |
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. |
partial |
Partially evaluate this operator with the given values. |
ready |
Check if the lazy value is ready to be evaluated. |
keys |
Get the set of symbol names required to evaluate this operator. |
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. |
partial
¶
partial(**values: Any) -> Any
Partially 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 |
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 |