hydra.ast module

A model which provides a common syntax tree for Hydra serializers.

class hydra.ast.Associativity(*values)

Bases: Enum

Operator associativity.

BOTH = Name(value='both')
LEFT = Name(value='left')
NONE = Name(value='none')
RIGHT = Name(value='right')
TYPE_ = Name(value='hydra.ast.Associativity')
class hydra.ast.BlockStyle(indent: Annotated[object, 'An optional indentation string'], newline_before_content: Annotated[bool, 'Whether to place a newline before the content'], newline_after_content: Annotated[bool, 'Whether to place a newline after the content'])

Bases: object

Formatting option for code blocks.

class Builder(_indent: 'Optional[str]' = None, _newline_before_content: 'bool' = None, _newline_after_content: 'bool' = None)

Bases: object

build()
indent(indent)
newline_after_content(newline_after_content)
newline_before_content(newline_before_content)
INDENT = Name(value='indent')
NEWLINE_AFTER_CONTENT = Name(value='newlineAfterContent')
NEWLINE_BEFORE_CONTENT = Name(value='newlineBeforeContent')
TYPE_ = Name(value='hydra.ast.BlockStyle')
static builder()
indent: Annotated[object, 'An optional indentation string']
newline_after_content: Annotated[bool, 'Whether to place a newline after the content']
newline_before_content: Annotated[bool, 'Whether to place a newline before the content']
with_indent(indent)
with_newline_after_content(newline_after_content)
with_newline_before_content(newline_before_content)
class hydra.ast.BracketExpr(brackets: Annotated[Brackets, 'The bracket pair enclosing the expression'], enclosed: Annotated[Expr, 'The expression within the brackets'], style: Annotated[BlockStyle, 'The formatting style for the bracketed block'])

Bases: object

An expression enclosed by brackets.

BRACKETS = Name(value='brackets')
class Builder(_brackets: 'Brackets' = None, _enclosed: 'Expr' = None, _style: 'BlockStyle' = None)

Bases: object

brackets(brackets)
build()
enclosed(enclosed)
style(style)
ENCLOSED = Name(value='enclosed')
STYLE = Name(value='style')
TYPE_ = Name(value='hydra.ast.BracketExpr')
brackets: Annotated[Brackets, 'The bracket pair enclosing the expression']
static builder()
enclosed: Annotated[Expr, 'The expression within the brackets']
style: Annotated[BlockStyle, 'The formatting style for the bracketed block']
with_brackets(brackets)
with_enclosed(enclosed)
with_style(style)
class hydra.ast.Brackets(open: Annotated[Symbol, 'The opening bracket symbol'], close: Annotated[Symbol, 'The closing bracket symbol'])

Bases: object

Matching open and close bracket symbols.

class Builder(_open: 'Symbol' = None, _close: 'Symbol' = None)

Bases: object

build()
close(close)
open(open)
CLOSE = Name(value='close')
OPEN = Name(value='open')
TYPE_ = Name(value='hydra.ast.Brackets')
static builder()
close: Annotated[Symbol, 'The closing bracket symbol']
open: Annotated[Symbol, 'The opening bracket symbol']
with_close(close)
with_open(open)
class hydra.ast.Expr

Bases: object

ExprConst | ExprIndent | ExprOp | ExprBrackets | ExprSeq

BRACKETS = Name(value='brackets')
CONST = Name(value='const')
INDENT = Name(value='indent')
OP = Name(value='op')
SEQ = Name(value='seq')
TYPE_ = Name(value='hydra.ast.Expr')
class hydra.ast.ExprBrackets(value: T)

Bases: Node[BracketExpr]

A bracketed expression

class hydra.ast.ExprConst(value: T)

Bases: Node[Symbol]

A constant symbol

class hydra.ast.ExprIndent(value: T)

Bases: Node[IndentedExpression]

An indented expression

class hydra.ast.ExprOp(value: T)

Bases: Node[OpExpr]

An operator expression

class hydra.ast.ExprSeq(value: T)

Bases: Node[SeqExpr]

A sequence of expressions joined by a separator, treated as structural layout (not subject to parenthesization)

class hydra.ast.IndentStyle

Bases: object

IndentStyleAllLines | IndentStyleSubsequentLines

ALL_LINES = Name(value='allLines')
SUBSEQUENT_LINES = Name(value='subsequentLines')
TYPE_ = Name(value='hydra.ast.IndentStyle')
class hydra.ast.IndentStyleAllLines(value: T)

Bases: Node[str]

Indent all lines with the given string

class hydra.ast.IndentStyleSubsequentLines(value: T)

Bases: Node[str]

Indent only lines after the first with the given string

class hydra.ast.IndentedExpression(style: Annotated[IndentStyle, 'The indentation style'], expr: Annotated[Expr, 'The expression to be indented'])

Bases: object

An expression indented in a certain style.

class Builder(_style: 'IndentStyle' = None, _expr: 'Expr' = None)

Bases: object

build()
expr(expr)
style(style)
EXPR = Name(value='expr')
STYLE = Name(value='style')
TYPE_ = Name(value='hydra.ast.IndentedExpression')
static builder()
expr: Annotated[Expr, 'The expression to be indented']
style: Annotated[IndentStyle, 'The indentation style']
with_expr(expr)
with_style(style)
class hydra.ast.Op(symbol: Annotated[Symbol, 'The operator symbol'], padding: Annotated[Padding, 'The padding around the operator'], precedence: Annotated[Precedence, 'The precedence of the operator'], associativity: Annotated[Associativity, 'The associativity of the operator'])

Bases: object

An operator symbol.

ASSOCIATIVITY = Name(value='associativity')
class Builder(_symbol: 'Symbol' = None, _padding: 'Padding' = None, _precedence: 'Precedence' = None, _associativity: 'Associativity' = None)

Bases: object

associativity(associativity)
build()
padding(padding)
precedence(precedence)
symbol(symbol)
PADDING = Name(value='padding')
PRECEDENCE = Name(value='precedence')
SYMBOL = Name(value='symbol')
TYPE_ = Name(value='hydra.ast.Op')
associativity: Annotated[Associativity, 'The associativity of the operator']
static builder()
padding: Annotated[Padding, 'The padding around the operator']
precedence: Annotated[Precedence, 'The precedence of the operator']
symbol: Annotated[Symbol, 'The operator symbol']
with_associativity(associativity)
with_padding(padding)
with_precedence(precedence)
with_symbol(symbol)
class hydra.ast.OpExpr(op: Annotated[Op, 'The operator'], lhs: Annotated[Expr, 'The left-hand side operand'], rhs: Annotated[Expr, 'The right-hand side operand'])

Bases: object

An operator expression.

class Builder(_op: 'Op' = None, _lhs: 'Expr' = None, _rhs: 'Expr' = None)

Bases: object

build()
lhs(lhs)
op(op)
rhs(rhs)
LHS = Name(value='lhs')
OP = Name(value='op')
RHS = Name(value='rhs')
TYPE_ = Name(value='hydra.ast.OpExpr')
static builder()
lhs: Annotated[Expr, 'The left-hand side operand']
op: Annotated[Op, 'The operator']
rhs: Annotated[Expr, 'The right-hand side operand']
with_lhs(lhs)
with_op(op)
with_rhs(rhs)
class hydra.ast.Padding(left: Annotated[Ws, 'Padding to the left of the operator'], right: Annotated[Ws, 'Padding to the right of the operator'])

Bases: object

Left and right padding for an operator.

class Builder(_left: 'Ws' = None, _right: 'Ws' = None)

Bases: object

build()
left(left)
right(right)
LEFT = Name(value='left')
RIGHT = Name(value='right')
TYPE_ = Name(value='hydra.ast.Padding')
static builder()
left: Annotated[Ws, 'Padding to the left of the operator']
right: Annotated[Ws, 'Padding to the right of the operator']
with_left(left)
with_right(right)
class hydra.ast.Precedence(value: T)

Bases: Node[int]

Operator precedence.

TYPE_ = Name(value='hydra.ast.Precedence')
class hydra.ast.SeqExpr(op: Annotated[Op, 'The separator operator'], elements: Annotated[Sequence[Expr], 'The expressions to join'])

Bases: object

A sequence of expressions joined by a separator operator. Unlike OpExpr, parenthesize ignores SeqExpr boundaries.

class Builder(_op: 'Op' = None, _elements: 'Sequence[Expr]' = None)

Bases: object

build()
elements(elements)
op(op)
ELEMENTS = Name(value='elements')
OP = Name(value='op')
TYPE_ = Name(value='hydra.ast.SeqExpr')
static builder()
elements: Annotated[Sequence[Expr], 'The expressions to join']
op: Annotated[Op, 'The separator operator']
with_elements(elements)
with_op(op)
class hydra.ast.Symbol(value: T)

Bases: Node[str]

Any symbol.

TYPE_ = Name(value='hydra.ast.Symbol')
class hydra.ast.Ws

Bases: object

WsNone | WsSpace | WsBreak | WsBreakAndIndent | WsDoubleBreak

BREAK = Name(value='break')
BREAK_AND_INDENT = Name(value='breakAndIndent')
DOUBLE_BREAK = Name(value='doubleBreak')
NONE = Name(value='none')
SPACE = Name(value='space')
TYPE_ = Name(value='hydra.ast.Ws')
class hydra.ast.WsBreak

Bases: object

A line break

class hydra.ast.WsBreakAndIndent(value: T)

Bases: Node[str]

A line break followed by indentation

class hydra.ast.WsDoubleBreak

Bases: object

Two line breaks

class hydra.ast.WsNone

Bases: object

No whitespace

class hydra.ast.WsSpace

Bases: object

A single space