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:

str

faust.utils.codegen.reprkwargs(kwargs: Mapping[str, Any], *, sep: str = ', ', fmt: str = '{0}={1}') str[source]
Return type:

str

faust.utils.codegen.reprcall(name: str, args: Tuple = (), kwargs: Mapping[str, Any] = {}, *, sep: str = ', ') str[source]
Return type:

str