faust.utils.codegen¶
Utilities for generating code at runtime.
- faust.utils.codegen.Function(name: str, args: ~typing.List[str], body: ~typing.List[str], *, globals: ~typing.Optional[~typing.Dict[str, ~typing.Any]] = None, locals: ~typing.Optional[~typing.Dict[str, ~typing.Any]] = None, return_type: ~typing.Any = <object object>, argsep: str = ', ') Callable[source]¶
Compile function code object from args and body.
- Return type:
_CallableType
- faust.utils.codegen.Method(name: str, args: List[str], body: List[str], **kwargs: Any) Callable[source]¶
Generate Python method.
- Return type:
_CallableType
- faust.utils.codegen.InitMethod(args: List[str], body: List[str], **kwargs: Any) Callable[[], None][source]¶
Generate
__init__method.- Return type:
_CallableGenericAlias[None]
- faust.utils.codegen.HashMethod(attrs: List[str], **kwargs: Any) Callable[[], None][source]¶
Generate
__hash__method.- Return type:
_CallableGenericAlias[None]
- faust.utils.codegen.CompareMethod(name: str, op: str, fields: List[str], **kwargs: Any) Callable[[], None][source]¶
Generate object comparison method.
Excellent for
__eq__,__le__, etc.Examples
The example:
CompareMethod( name='__eq__', op='==', fields=['x', 'y'], )
Generates a method like this:
def __eq__(self, other): if other.__class__ is self.__class__: return (self.x,self.y) == (other.x,other.y) return NotImplemented
- Return type:
_CallableGenericAlias[None]
- faust.utils.codegen.EqMethod(fields: List[str], **kwargs: Any) Callable[[], None][source]¶
Generate
__eq__method.- Return type:
_CallableGenericAlias[None]
- faust.utils.codegen.NeMethod(fields: List[str], **kwargs: Any) Callable[[], None][source]¶
Generate
__ne__method.- Return type:
_CallableGenericAlias[None]
- faust.utils.codegen.LeMethod(fields: List[str], **kwargs: Any) Callable[[], None][source]¶
Generate
__le__method.- Return type:
_CallableGenericAlias[None]
- faust.utils.codegen.LtMethod(fields: List[str], **kwargs: Any) Callable[[], None][source]¶
Generate
__lt__method.- Return type:
_CallableGenericAlias[None]
- faust.utils.codegen.GeMethod(fields: List[str], **kwargs: Any) Callable[[], None][source]¶
Generate
__ge__method.- Return type:
_CallableGenericAlias[None]
- faust.utils.codegen.GtMethod(fields: List[str], **kwargs: Any) Callable[[], None][source]¶
Generate
__gt__method.- Return type:
_CallableGenericAlias[None]
- faust.utils.codegen.build_function(name: str, source: str, *, return_type: ~typing.Any = <object object>, globals: ~typing.Optional[~typing.Dict[str, ~typing.Any]] = None, locals: ~typing.Optional[~typing.Dict[str, ~typing.Any]] = None) Callable[source]¶
Generate function from Python from source code string.
- Return type:
_CallableType
- faust.utils.codegen.build_function_source(name: str, args: ~typing.List[str], body: ~typing.List[str], *, return_type: ~typing.Any = <object object>, indentlevel: int = 0, indentspaces: int = 4, argsep: str = ', ') str[source]¶
Generate function source code from args and body.
- Return type: