hydra.python.utils module
Python utilities for constructing Python syntax trees.
- hydra.python.utils.annotated_expression(mcomment: object, expr: Expression) Expression
Annotate an expression with an optional comment using Annotated[].
- hydra.python.utils.annotated_statement(mcomment: object, stmt: Statement) Statement
Annotate a statement with an optional comment.
- hydra.python.utils.assignment(name: Name, rhs: AnnotatedRhs) Statement
Create an assignment statement from name and annotated rhs.
- hydra.python.utils.assignment_statement(name: Name, expr: Expression) Statement
Create an assignment statement from name and expression.
- hydra.python.utils.cast_to(pytype: Expression, pyexpr: Expression) Expression
Create a cast expression: cast(type, expr).
- hydra.python.utils.comment_statement(s: str) Statement
Create a comment statement (triple-quoted string).
- hydra.python.utils.decode_py_comparison_to_py_await_primary(c: Comparison) object
Decode a Comparison to a Primary if possible.
- hydra.python.utils.decode_py_conjunction_to_py_primary(c: Conjunction) object
Decode a Conjunction to a Primary if possible.
- hydra.python.utils.decode_py_expression_to_py_primary(e: Expression) object
Decode an Expression to a Primary if possible.
- hydra.python.utils.decode_py_inversion_to_py_primary(i: Inversion) object
Decode an Inversion to a Primary if possible.
- hydra.python.utils.decode_py_power_to_py_primary(p: Power) object
Decode a Power to a Primary if possible.
- hydra.python.utils.dotted_assignment_statement(obj: Name, attr: Name, expr: Expression) Statement
Create a dotted assignment statement: obj.attr = expr.
- hydra.python.utils.double_quoted_string(s: str) Expression
Create a double-quoted string expression.
- hydra.python.utils.find_namespaces(overlay_subs: Set[str], focus_ns: ModuleName, defs: Sequence[Definition]) ModuleNames[DottedName]
Find all namespaces referenced by a list of definitions, plus the core namespace (#630: overlaySubs drives emission-time hydra.lib.<sub> redirect for these namespace refs).
- hydra.python.utils.function_call(func: Primary, args: Sequence[Expression]) Expression
Create a function call expression.
- hydra.python.utils.get_item_params() Parameters
- hydra.python.utils.indented_block(mcomment: object, stmts: Sequence[Sequence[Statement]]) Block
Create an indented block with optional comment.
- hydra.python.utils.name_and_params(py_name: Name, params: Sequence[Expression]) Expression
Create a name with parameters.
- hydra.python.utils.newtype_statement(name: Name, mcomment: object, expr: Expression) Statement
Create a NewType statement.
- hydra.python.utils.or_expression(prims: Sequence[Primary]) Expression
Build an or-expression from multiple primaries.
- hydra.python.utils.primary_and_params(prim: Primary, params: Sequence[Expression]) Expression
Create a primary with parameters (subscript).
- hydra.python.utils.primary_with_expression_slices(prim: Primary, exprs: Sequence[Expression]) Primary
Create a Primary with expression slices.
- hydra.python.utils.primary_with_rhs(prim: Primary, rhs: PrimaryRhs) Primary
Combine a Primary with a PrimaryRhs.
- hydra.python.utils.primary_with_slices(prim: Primary, first: Slice, rest: Sequence[SliceOrStarredExpression]) Primary
Create a Primary with slices.
- hydra.python.utils.project_from_expression(exp: Expression, name: Name) Expression
Project a field from an expression.
- hydra.python.utils.py_assignment_to_py_statement(a: Assignment) Statement
Convert an Assignment to a Statement.
- hydra.python.utils.py_atom_to_py_expression(atom: Atom) Expression
Convert an Atom to an Expression.
- hydra.python.utils.py_bitwise_or_to_py_conjunction(bor: BitwiseOr) Conjunction
Convert a BitwiseOr to a Conjunction.
- hydra.python.utils.py_bitwise_or_to_py_expression(bor: BitwiseOr) Expression
Convert a BitwiseOr to an Expression.
- hydra.python.utils.py_class_definition_to_py_statement(cd: ClassDefinition) Statement
Convert a ClassDefinition to a Statement.
- hydra.python.utils.py_closed_pattern_to_py_patterns(p: ClosedPattern) Patterns
Convert a ClosedPattern to Patterns.
- hydra.python.utils.py_conjunction_to_py_expression(conj: Conjunction) Expression
Convert a Conjunction to an Expression.
- hydra.python.utils.py_expression_to_bitwise_or(e: Expression) BitwiseOr
Convert an Expression to a BitwiseOr, wrapping in parens if needed.
- hydra.python.utils.py_expression_to_disjunction(e: Expression) Disjunction
Convert an Expression to a Disjunction, wrapping in parens if needed.
- hydra.python.utils.py_expression_to_py_annotated_rhs(expr: Expression) AnnotatedRhs
Convert an Expression to an AnnotatedRhs.
- hydra.python.utils.py_expression_to_py_primary(e: Expression) Primary
Extracts the primary from an expression, or wraps it in parentheses if the expression does not contain a primary.
- hydra.python.utils.py_expression_to_py_simple_statement(expr: Expression) SimpleStatement
Convert an Expression to a SimpleStatement (as star expressions).
- hydra.python.utils.py_expression_to_py_slice(expr: Expression) Slice
Convert an Expression to a Slice.
- hydra.python.utils.py_expression_to_py_star_named_expression(expr: Expression) StarNamedExpression
Convert an Expression to a StarNamedExpression.
- hydra.python.utils.py_expression_to_py_statement(expr: Expression) Statement
Convert an Expression to a Statement.
- hydra.python.utils.py_expressions_to_py_args(exprs: Sequence[Expression]) Args
Convert a list of Expressions to Args.
- hydra.python.utils.py_list(exprs: Sequence[Expression]) List
Create a Python list from expressions.
- hydra.python.utils.py_name_to_py_expression(name: Name) Expression
Convert a Name to an Expression.
- hydra.python.utils.py_name_to_py_named_expression(name: Name) NamedExpression
Convert a Name to a NamedExpression.
- hydra.python.utils.py_name_to_py_primary(name: Name) Primary
Convert a Name to a Primary (simple atom).
- hydra.python.utils.py_name_to_py_star_target(name: Name) StarTarget
Convert a Name to a StarTarget.
- hydra.python.utils.py_name_to_py_type_parameter(name: Name) TypeParameter
Convert a Name to a TypeParameter.
- hydra.python.utils.py_primary_to_py_bitwise_or(prim: Primary) BitwiseOr
Convert a Primary to a BitwiseOr.
- hydra.python.utils.py_primary_to_py_bitwise_xor(prim: Primary) BitwiseXor
Convert a Primary to a BitwiseXor.
- hydra.python.utils.py_primary_to_py_conjunction(prim: Primary) Conjunction
Convert a Primary to a Conjunction.
- hydra.python.utils.py_primary_to_py_expression(prim: Primary) Expression
Convert a Primary to an Expression.
- hydra.python.utils.py_simple_statement_to_py_statement(s: SimpleStatement) Statement
Convert a SimpleStatement to a Statement.
- hydra.python.utils.raise_assertion_error(msg: str) Statement
Create a raise AssertionError statement.
- hydra.python.utils.return_single(expr: Expression) Statement
Create a return statement with a single expression.
- hydra.python.utils.self_only_params() Parameters
- hydra.python.utils.self_other_params() Parameters
- hydra.python.utils.single_quoted_string(s: str) Expression
Create a single-quoted string expression.
- hydra.python.utils.string_to_py_expression(style: QuoteStyle, s: str) Expression
Create a string expression with a given quote style.
- hydra.python.utils.triple_quoted_string(s: str) Expression
Create a raw triple-double-quoted string expression (Python docstring convention). Raw-prefixed so embedded backslashes (e.g. lambda notation x.e) aren’t interpreted as escape sequences by Python’s string parser.
- hydra.python.utils.type_alias_statement(name: Name, tparams: Sequence[TypeParameter], mcomment: object, tyexpr: Expression) Statement
Generate a type alias statement using PEP 695 syntax (Python 3.12+).
- hydra.python.utils.type_alias_statement310(name: Name, _tparams: T0, mcomment: object, tyexpr: Expression) Statement
Generate a type alias statement using Python 3.10-compatible syntax: Name: TypeAlias = “TypeExpression”.
- hydra.python.utils.union_type_class_statements310(name: Name, mcomment: object, tyexpr: Expression, extra_stmts: Sequence[Statement]) Sequence[Statement]
Generate a subscriptable union class for Python 3.10.