faust.utils.codegen

Utilities for generating code at runtime.

faust.utils.codegen.Function(name: str, args: List[str], body: List[str], *, globals: Dict[str, Any] = None, locals: Dict[str, Any] = None, return_type: Any = <object object>, argsep: str = ', ') → Callable[source]

Generate a function from Python.

Return type:Callable
faust.utils.codegen.Method(name: str, args: List[str], body: List[str], **kwargs) → Callable[source]

Generate Python method.

Return type:Callable
faust.utils.codegen.InitMethod(args: List[str], body: List[str], **kwargs) → Callable[None][source]

Generate __init__ method.

Return type:Callable[[], None]
faust.utils.codegen.HashMethod(attrs: List[str], **kwargs) → Callable[None][source]

Generate __hash__ method.

Return type:Callable[[], None]
faust.utils.codegen.EqMethod(fields: List[str], **kwargs) → Callable[None][source]

Generate __eq__ method.

Return type:Callable[[], None]
faust.utils.codegen.NeMethod(fields: List[str], **kwargs) → Callable[None][source]

Generate __ne__ method.

Return type:Callable[[], None]
faust.utils.codegen.GeMethod(fields: List[str], **kwargs) → Callable[None][source]

Generate __ge__ method.

Return type:Callable[[], None]
faust.utils.codegen.GtMethod(fields: List[str], **kwargs) → Callable[None][source]

Generate __gt__ method.

Return type:Callable[[], None]
faust.utils.codegen.LeMethod(fields: List[str], **kwargs) → Callable[None][source]

Generate __le__ method.

Return type:Callable[[], None]
faust.utils.codegen.LtMethod(fields: List[str], **kwargs) → Callable[None][source]

Generate __lt__ method.

Return type:Callable[[], None]
faust.utils.codegen.CompareMethod(name: str, op: str, fields: List[str], **kwargs) → 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:Callable[[], None]