hydra.ast module
A model which provides a common syntax tree for Hydra serializers.
- class hydra.ast.Associativity(*values)
Bases:
EnumOperator 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:
objectFormatting 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()
- 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:
objectAn 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')
- static builder()
- 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:
objectMatching 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()
- with_close(close)
- with_open(open)
- class hydra.ast.Expr
Bases:
objectExprConst | 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.ExprIndent(value: T)
Bases:
Node[IndentedExpression]An indented expression
- class hydra.ast.ExprSeq(value: T)
-
A sequence of expressions joined by a separator, treated as structural layout (not subject to parenthesization)
- class hydra.ast.IndentStyle
Bases:
objectIndentStyleAllLines | 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:
objectAn 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()
- 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:
objectAn 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()
- precedence: Annotated[Precedence, 'The precedence of the operator']
- 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:
objectAn 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()
- 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:
objectLeft 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()
- 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:
objectA 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()
- 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:
objectWsNone | 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:
objectA line break
- class hydra.ast.WsDoubleBreak
Bases:
objectTwo line breaks
- class hydra.ast.WsNone
Bases:
objectNo whitespace
- class hydra.ast.WsSpace
Bases:
objectA single space