API Reference

class genpy.Generable[source]

A base class for AST nodes capable of generating code.

__str__() str[source]

Return a single string (possibly containing newlines) representing this code construct.

abstract generate() Iterator[str][source]

Generate (i.e. yield) the lines making up this code construct.

class genpy.Suite(contents: Iterable[Generable] | Generable | None = None)[source]

Bases: Generable

__init__(contents: Iterable[Generable] | Generable | None = None) None[source]
generate() Iterator[str][source]

Generate (i.e. yield) the lines making up this code construct.

append(data: Generable) None[source]
extend(data: Iterable[Generable]) None[source]
insert(i: int, data: Generable) None[source]
extend_log_block(descr: str, data: Iterable[Generable]) None[source]
class genpy.Collection(contents: Iterable[Generable] | Generable | None = None)[source]

Bases: Suite

Like Suite, but does not lead to indentation.

Block nodes

class genpy.Class(name: str, bases: Iterable[str], attributes: Iterable[Generable])[source]

Bases: Generable

A class definition.

__init__(name: str, bases: Iterable[str], attributes: Iterable[Generable]) None[source]
class genpy.If(condition: str, then_: Generable, else_: Generable | None = None)[source]

Bases: Generable

An if/then/else block.

__init__(condition: str, then_: Generable, else_: Generable | None = None) None[source]
class genpy.Loop(body: Generable)[source]

Bases: Generable, ABC

An abstract base class for loops. class for loop blocks.

__init__(body: Generable) None[source]
abstract intro_line() str | None[source]
outro_line() str | None[source]
class genpy.CustomLoop(intro_line: str | None, body: Generable, outro_line: str | None = None)[source]

Bases: Loop

__init__(intro_line: str | None, body: Generable, outro_line: str | None = None) None[source]
class genpy.While(condition: str, body: Generable)[source]

Bases: Loop

__init__(condition: str, body: Generable)[source]
class genpy.For(vars: str | tuple[str, ...], iterable: str, body: Generable)[source]

Bases: Loop

__init__(vars: str | tuple[str, ...], iterable: str, body: Generable) None[source]
class genpy.Function(name: str, args: Iterable[str], body: Generable, decorators: Iterable[str] = ())[source]

Bases: Generable

__init__(name: str, args: Iterable[str], body: Generable, decorators: Iterable[str] = ()) None[source]
genpy.make_multiple_ifs(conditions_and_blocks: Sequence[tuple[str, Generable]], base: Generable | Literal['last'] | None = None) Generable | None[source]

Single (logical) line Nodes

class genpy.Import(module: str)[source]

Bases: Generable

__init__(module: str) None[source]
class genpy.ImportAs(module: str, as_: str)[source]

Bases: Generable

__init__(module: str, as_: str) None[source]
class genpy.FromImport(module: str, names: Iterable[str])[source]

Bases: Generable

__init__(module: str, names: Iterable[str]) None[source]
class genpy.Statement(text: str)[source]

Bases: Generable

__init__(text: str) None[source]
class genpy.Assign(lvalue: str, rvalue: str)[source]

Bases: Generable

__init__(lvalue: str, rvalue: str) None[source]
class genpy.Line(text: str = '')[source]

Bases: Generable

__init__(text: str = '') None[source]
class genpy.Return(expr: str)[source]

Bases: Generable

__init__(expr: str) None[source]
class genpy.Raise(expr: str)[source]

Bases: Generable

__init__(expr: str) None[source]
class genpy.Assert(expr: str)[source]

Bases: Generable

__init__(expr: str) None[source]
class genpy.Yield(expr: str)[source]

Bases: Generable

__init__(expr: str) None[source]
class genpy.Pass[source]

Bases: Generable

__init__()
class genpy.Comment(text: str)[source]

Bases: Generable

__init__(text: str) None[source]