pygritia.core module¶
Core functionality for lazy expressions
-
class
pygritia.core.LazyAction[source]¶ Bases:
objectLazy Expression Handler
Every derived LazyAction classes must implements
evaluate()method. It is called byevaluate()function with given namespace-
evaluate(namespace: Mapping[Union[str, LazyMixin], Any]) → Any[source]¶ Evaluate expression
To substitute actual value for specific symbol, give value with keyword argument.
-
owner¶ Owner lazy expression of this action
-
-
class
pygritia.core.LazyMeta[source]¶ Bases:
typeMetaclass for
LazyIt is for holding global
Lazyfactory and creation-
classmethod
create(action: pygritia.core.LazyAction, origin: Optional[LazyMixin] = None) → pygritia.core.LazyMixin[source]¶ Create new lazy expression with given action by default lazy factory
Parameters: - action (LazyAction) – Evaluation/update handler for new lazy expression
- origin (Optional[LazyMixin]) – Lazy expression which cause creation of new expression
Returns: Newly created lazy expression
Return type:
-
classmethod
-
class
pygritia.core.LazyMixin(action: pygritia.core.LazyAction, origin: Optional[LazyMixin] = None)[source]¶ Bases:
objectBase class of all lazy expression and mixin classes
It provides Protocol for lazy expression
All derived classes of this class have
__hash__automatically, because namespace for evaluate is defined as lazy expression (normally symbol only) to value mapping. Key of mapping must be hashable.
-
pygritia.core.evaluate(expr: _T, namespace: Mapping[Union[str, LazyMixin], Any]) → _T[source]¶ Evaluate lazy expression
Evaluate expression with symbol substitution according to given
namespaceParameters: - expr –
Lazy expression or evaluated value
If given value is not a lazy expression, this function returns it immediately
- namespace –
Symbol table which will be used in substitution
The key of table can be both of string and symbol expression
Returns: Evaluated value
- expr –
-
pygritia.core.repr_(expr: Any) → str[source]¶ repr()for lazy expressionNative
reprreturns string like'<Lazy: this>'. If you want to get the repr string like other objects, use this instead of native one. It returns expression only for lazy expression andrepr()for other object.Parameters: expr – object for repr Returns: repr string of given object
-
pygritia.core.setattr_¶ Implement setattr(self, name, value).
-
pygritia.core.update(expr: _T, val: _T, namespace: Mapping[Union[str, LazyMixin], Any]) → None[source]¶ Update the value of lazy expression
Set the value of lazy expression to the given
valOnly assignable expression can be updated. ex)this[3],this.spamParameters: - expr – Assignable lazy expression
- val – New value
- namespace –
Symbol table which will be used in substitution
The key of table can be both of string and symbol expression