hydra.python.coder module
Python code generator: converts Hydra modules to Python source code.
- hydra.python.coder.analyze_python_function(cx: InferenceContext, env: PythonEnvironment, term: Term) object
Analyze a function term with Python-specific Graph management.
- hydra.python.coder.builder_setter_name(env: PythonEnvironment, fname: Name) str
Escape a builder setter name that would collide with build()/builder()/self.
- hydra.python.coder.case_block_to_expr(cx: T0, env: PythonEnvironment, tname: Name, row_type: Sequence[FieldType], is_enum: bool, encode_body: Callable[[PythonEnvironment, Term], object], field: CaseAlternative) object
Encode a single case (Field) into a CaseBlock for a match statement.
- hydra.python.coder.class_variant_pattern_unit(py_variant_name: Name) ClosedPattern
Create a class pattern for a unit variant (no value captured).
- hydra.python.coder.class_variant_pattern_with_capture(env: PythonEnvironment, py_variant_name: Name, var_name: Name) ClosedPattern
Create a class pattern for a variant with captured value.
- hydra.python.coder.collect_type_variables(initial: Set[Name], typ: Type) Set[Name]
Collect type variables from a type.
- hydra.python.coder.cond_import_symbol(name: T0, flag: bool) object
Conditionally include a symbol name based on a boolean flag.
- hydra.python.coder.dataclass_decorator() NamedExpression
Create a @dataclass(frozen=True) decorator.
- hydra.python.coder.deconflict_variant_name(is_qualified: bool, env: PythonEnvironment, union_name: Name, fname: Name, g: Graph) Name
Deconflict a variant name to avoid collisions with type names.
- hydra.python.coder.deduplicate_case_variables(cases_: Sequence[CaseAlternative]) Sequence[CaseAlternative]
Rewrite case statements to avoid variable name collisions.
- hydra.python.coder.dig_for_wrap(is_term_annot: bool, meta: PythonModuleMetadata, typ: Type) PythonModuleMetadata
Recursively dig through forall types to find wrap types.
- hydra.python.coder.eliminate_unit_var(v: Name, term0: Term) Term
Substitute unit for a variable in a term (for unit variant case handling).
- hydra.python.coder.empty_metadata(ns: ModuleNames[DottedName]) PythonModuleMetadata
Create an initial empty metadata record with given namespaces.
- hydra.python.coder.encode_application(cx: InferenceContext, env: PythonEnvironment, app: Application) object
Encode a function application to a Python expression.
- hydra.python.coder.encode_application_inner(cx: InferenceContext, env: PythonEnvironment, fun: Term, hargs: Sequence[Expression], rargs: Sequence[Expression]) object
Inner helper for encodeApplication.
- hydra.python.coder.encode_application_type(env: PythonEnvironment, at: ApplicationType) object
Encode an application type to Python expression.
- hydra.python.coder.encode_binding_as(cx: InferenceContext, env: PythonEnvironment, binding: Binding) object
Encode a binding as a Python statement (function definition or assignment).
- hydra.python.coder.encode_binding_as_assignment(cx: InferenceContext, allow_thunking: bool, env: PythonEnvironment, binding: Binding) object
Encode a binding as a walrus operator assignment.
- hydra.python.coder.encode_bindings_as_defs(env: T0, encode_binding: Callable[[T0, T1], object], bindings: Sequence[T1]) object
Encode bindings as function definitions.
- hydra.python.coder.encode_default_case_block(term_to_expr: Callable[[T0], object], is_full: bool, mdflt: object, tname: Name) object
Encode the default (wildcard) case block for a match statement.
- hydra.python.coder.encode_definition(cx: InferenceContext, env: PythonEnvironment, def_: Definition) object
Encode a definition (term or type) to Python statements.
- hydra.python.coder.encode_enum_value_assignment(cx: T0, env: PythonEnvironment, field_type: FieldType) object
Encode an enum value assignment statement with optional comment.
- hydra.python.coder.encode_field(cx: T0, env: PythonEnvironment, field: Field, term_to_expr: Callable[[Term], object]) object
Encode a field (name-value pair) to a Python (Name, Expression) pair.
- hydra.python.coder.encode_field_type(cx: T0, env: PythonEnvironment, field_type: FieldType) object
Encode a field type for record definitions (field: type annotation).
- hydra.python.coder.encode_float_value(fv: FloatValue) object
Encode a float value to a Python expression.
- hydra.python.coder.encode_float_value_encode_float32(v: float) object
- hydra.python.coder.encode_float_value_encode_float64(v: float) object
- hydra.python.coder.encode_float_value_py_special_float(value: str) Expression
- hydra.python.coder.encode_forall_type(env: PythonEnvironment, lt: ForallType) object
Encode a forall type to Python expression.
- hydra.python.coder.encode_function_type(env: PythonEnvironment, ft: FunctionType) object
Encode a function type to Python Callable expression.
- hydra.python.coder.encode_integer_value(iv: IntegerValue) object
Encode an integer value to a Python expression.
- hydra.python.coder.encode_literal(lit: Literal) object
Encode a literal value to a Python expression.
- hydra.python.coder.encode_literal_type(lt: LiteralType) object
Encode a literal type to a Python type expression.
- hydra.python.coder.encode_name_constants(env: PythonEnvironment, name: Name, fields: Sequence[FieldType]) Sequence[Statement]
Generate name constants for a type as class-level attributes.
- hydra.python.coder.encode_python_module(overlay_subs: Set[str], cx: InferenceContext, g: Graph, mod: Module, defs0: Sequence[Definition]) object
Encode a Hydra module to a Python module AST, given the on-disk overlay-existence set (#630) driving emission-time primitive-reference redirects.
- hydra.python.coder.encode_record_type(cx: T0, env: PythonEnvironment, name: Name, row_type: Sequence[FieldType], comment: object) object
Encode a record type as a Python dataclass.
- hydra.python.coder.encode_term_assignment(cx: InferenceContext, env: PythonEnvironment, top_level: bool, name: Name, term: Term, ts: TypeScheme, comment: object) object
Encode a term assignment to a Python statement.
- hydra.python.coder.encode_term_inline(cx: InferenceContext, env: PythonEnvironment, no_cast: bool, term: Term) object
Encode a term to a Python expression (inline form).
- hydra.python.coder.encode_term_multiline(cx: InferenceContext, env: PythonEnvironment, term: Term) object
Encode a term to a list of statements with return as final statement.
- hydra.python.coder.encode_term_multiline_t_c_o(cx: InferenceContext, env: PythonEnvironment, func_name: Name, param_names: Sequence[Name], term: Term) object
Encode a term body for TCO: tail self-calls become param reassignment + continue.
- hydra.python.coder.encode_type(env: PythonEnvironment, typ: Type) object
Encode a Hydra type to a Python type expression.
- hydra.python.coder.encode_type_assignment(cx: T0, env: PythonEnvironment, name: Name, typ: Type, comment: object) object
Encode a type definition, dispatching based on type structure.
- hydra.python.coder.encode_type_assignment_inner(cx: T0, env: PythonEnvironment, name: Name, typ: Type, comment: object) object
Encode the inner type definition, unwrapping forall types.
- hydra.python.coder.encode_type_def_single(env: PythonEnvironment, name: Name, comment: object, type_expr: Expression) Sequence[Statement]
Encode a simple type alias definition.
- hydra.python.coder.encode_type_quoted(env: PythonEnvironment, typ: Type) object
Encode a type to a Python expression, quoting if the type has free variables.
- hydra.python.coder.encode_union_elimination_inline(cx: InferenceContext, env: PythonEnvironment, cs: CaseStatement, py_arg: Expression) object
Encode a union elimination as an inline conditional chain (isinstance-based ternary).
- hydra.python.coder.encode_union_field(cx: T0, env: PythonEnvironment, union_name: Name, field_type: FieldType) object
Encode a union field as a variant class.
- hydra.python.coder.encode_union_field_alt(env: PythonEnvironment, union_name: Name, field_type: FieldType) Primary
Encode a union field as a primary expression for | alternatives.
- hydra.python.coder.encode_union_type(cx: T0, env: PythonEnvironment, name: Name, row_type: Sequence[FieldType], comment: object) object
Encode a union type as an enum (for unit-only fields) or variant classes.
- hydra.python.coder.encode_variable(cx: T0, env: PythonEnvironment, name: Name, args: Sequence[Expression]) object
Encode a variable reference to a Python expression.
- hydra.python.coder.encode_wrapped_type(env: PythonEnvironment, name: Name, typ: Type, comment: object) object
Encode a wrapped type (newtype) to a Python class definition.
- hydra.python.coder.enum_variant_pattern(env: PythonEnvironment, type_name: Name, field_name: Name) ClosedPattern
Create a value pattern for an enum variant.
- hydra.python.coder.environment_type_parameters(env: PythonEnvironment) Sequence[TypeParameter]
Get type parameters from environment as Python TypeParameters.
- hydra.python.coder.extend_env_with_lambda_params(env: PythonEnvironment, term: Term) PythonEnvironment
Extend environment with lambda parameters from a term.
- hydra.python.coder.extend_env_with_type_var(env: PythonEnvironment, var_: Name) PythonEnvironment
Extend a PythonEnvironment with a new bound type variable.
- hydra.python.coder.extend_meta_for_term(top_level: bool, meta0: PythonModuleMetadata, term: Term) PythonModuleMetadata
Extend metadata based on a term (used during module encoding).
- hydra.python.coder.extend_meta_for_type(top_level: bool, is_term_annot: bool, typ: Type, meta: PythonModuleMetadata) PythonModuleMetadata
Extend metadata based on a type (used during module encoding).
- hydra.python.coder.extend_meta_for_types(types: Sequence[Type], meta: PythonModuleMetadata) PythonModuleMetadata
Extend metadata for a list of types.
- hydra.python.coder.extract_case_elimination(term: Term) object
Extract CaseStatement from a case elimination term.
- hydra.python.coder.fill_doms_from_signature(doms: Sequence[T0], sig_param_types: Sequence[T0]) Sequence[T0]
Prefer signature parameter types over analysis-captured lambda domains when both are available in equal length (#488).
- hydra.python.coder.find_type_params(env: PythonEnvironment, typ: Type) Sequence[Name]
Find type parameters in a type that are bound in the environment.
- hydra.python.coder.function_definition_to_expr(cx: InferenceContext, env: PythonEnvironment, name: Name, tparams: Sequence[Name], args: Sequence[Name], body: Term, doms: Sequence[Type], mcod: object, comment: object, prefixes: Sequence[Statement]) object
Encode a function definition with parameters and body.
- hydra.python.coder.gather_lambdas(term: Term) tuple[Sequence[Name], Term]
Extract lambdas and their bodies from a term.
- hydra.python.coder.gather_metadata(overlay_subs: Set[str], focus_ns: ModuleName, defs: Sequence[Definition]) PythonModuleMetadata
Gather metadata from definitions.
- hydra.python.coder.generic_arg(tparam_list: Sequence[Name]) object
Create Generic[…] argument expression for class definition.
- hydra.python.coder.initial_environment(namespaces: ModuleNames[DottedName], tcontext: Graph, overlay_subs: Set[str]) PythonEnvironment
Create an initial Python environment for code generation, given the on-disk overlay-existence set (#630) driving emission-time primitive-reference redirects.
- hydra.python.coder.initial_metadata(ns: ModuleName) PythonModuleMetadata
Create initial empty metadata for a Python module.
- hydra.python.coder.is_case_statement_application(term: Term) object
Check if a term is a case statement applied to exactly one argument.
- hydra.python.coder.is_cases_full(row_type: Sequence[T0], cases_: Sequence[T1]) bool
Check if union cases are fully covered.
- hydra.python.coder.is_type_module_check(defs: Sequence[Definition]) bool
Check whether a list of definitions contains any type definitions.
- hydra.python.coder.is_type_variable_name(name: Name) bool
Check if a name is a type variable (unqualified - no dots).
- hydra.python.coder.is_variant_unit_type(row_type: Sequence[FieldType], field_name: Name) bool
Check if a variant field has unit type.
- hydra.python.coder.lazy_dot_get(expr: Expression) Expression
Wrap an expression in a .get() method call (for Lazy unwrap at use sites).
- hydra.python.coder.lazy_flags_for_primitive(g: Graph, name: Name) Sequence[bool]
Per-parameter isLazy flags of a primitive (by name), or empty if not a primitive. Single source of truth for which arguments coders thunk; replaces hard-coded name tables (issue #391).
- hydra.python.coder.lru_cache_decorator() NamedExpression
Decorator for @lru_cache(1) to memoize zero-argument function results.
- hydra.python.coder.make_curried_lambda(params: Sequence[Name], body: Expression) Expression
Create a curried lambda chain from a list of parameter names and a body.
- hydra.python.coder.make_lazy(pbody: Expression) Expression
Wrap an expression in Lazy(lambda: …) for one-shot lazy memoization.
- hydra.python.coder.make_py_graph(g: Graph, m: PythonModuleMetadata) PyGraph
Constructor for PyGraph record.
- hydra.python.coder.make_simple_lambda(arity: int, lhs: Expression) Expression
Wrap a bare reference to a polymorphic function in an uncurried lambda.
- hydra.python.coder.make_thunk(pbody: Expression) Expression
Create a thunk (zero-argument lambda) wrapped with lru_cache(1) for memoization.
- hydra.python.coder.make_uncurried_lambda(params: Sequence[Name], body: Expression) Expression
Create an uncurried lambda with multiple parameters.
- hydra.python.coder.module_domain_imports(namespaces: ModuleNames[DottedName]) Sequence[ImportStatement]
Generate domain import statements from namespace mappings.
- hydra.python.coder.module_imports(namespaces: ModuleNames[DottedName], meta: PythonModuleMetadata) Sequence[Statement]
Generate all import statements for a Python module.
- hydra.python.coder.module_standard_imports(meta: PythonModuleMetadata) Sequence[ImportStatement]
Generate standard import statements based on module metadata.
- hydra.python.coder.module_to_python(overlay_subs: Set[str], mod: Module, defs: Sequence[Definition], cx: InferenceContext, g: Graph) object
Convert a Hydra module to Python source files.
- hydra.python.coder.py_graph_metadata(pyg: PyGraph) PythonModuleMetadata
Accessor for the metadata field of PyGraph.
- hydra.python.coder.py_int(n: int) Expression
Create integer literal expression.
- hydra.python.coder.python_binding_metadata(g: Graph, b: Binding) object
Like bindingMetadata, but only for bindings that will actually be thunked.
- hydra.python.coder.python_environment_get_graph(env: PythonEnvironment) Graph
Get the Graph from a PythonEnvironment.
- hydra.python.coder.python_environment_set_graph(tc: Graph, env: PythonEnvironment) PythonEnvironment
Set the Graph in a PythonEnvironment.
- hydra.python.coder.record_builder_class(env: PythonEnvironment, name: Name, row_type: Sequence[FieldType], record_args: object) object
Build a fluent builder (factory + nested Builder dataclass) for a record.
- hydra.python.coder.record_builder_setter(env: PythonEnvironment, field_type: FieldType) Statement
Build a fluent setter for the nested Builder of a record.
- hydra.python.coder.record_with_method(env: PythonEnvironment, field_type: FieldType) Statement
Build a per-field copy-update method (with_<field>) for a record.
- hydra.python.coder.set_meta_namespaces(ns: ModuleNames[DottedName], m: PythonModuleMetadata) PythonModuleMetadata
- hydra.python.coder.set_meta_type_variables(m: PythonModuleMetadata, tvars: Set[Name]) PythonModuleMetadata
- hydra.python.coder.set_meta_uses_annotated(m: PythonModuleMetadata, b: bool) PythonModuleMetadata
- hydra.python.coder.set_meta_uses_callable(m: PythonModuleMetadata, b: bool) PythonModuleMetadata
- hydra.python.coder.set_meta_uses_cast(b: bool, m: PythonModuleMetadata) PythonModuleMetadata
- hydra.python.coder.set_meta_uses_dataclass(m: PythonModuleMetadata, b: bool) PythonModuleMetadata
- hydra.python.coder.set_meta_uses_decimal(m: PythonModuleMetadata, b: bool) PythonModuleMetadata
- hydra.python.coder.set_meta_uses_either(m: PythonModuleMetadata, b: bool) PythonModuleMetadata
- hydra.python.coder.set_meta_uses_enum(m: PythonModuleMetadata, b: bool) PythonModuleMetadata
- hydra.python.coder.set_meta_uses_frozen_dict(m: PythonModuleMetadata, b: bool) PythonModuleMetadata
- hydra.python.coder.set_meta_uses_frozen_list(m: PythonModuleMetadata, b: bool) PythonModuleMetadata
- hydra.python.coder.set_meta_uses_frozen_set(m: PythonModuleMetadata, b: bool) PythonModuleMetadata
- hydra.python.coder.set_meta_uses_generic(m: PythonModuleMetadata, b: bool) PythonModuleMetadata
- hydra.python.coder.set_meta_uses_just(m: PythonModuleMetadata, b: bool) PythonModuleMetadata
- hydra.python.coder.set_meta_uses_left(m: PythonModuleMetadata, b: bool) PythonModuleMetadata
- hydra.python.coder.set_meta_uses_lru_cache(b: bool, m: PythonModuleMetadata) PythonModuleMetadata
- hydra.python.coder.set_meta_uses_maybe(m: PythonModuleMetadata, b: bool) PythonModuleMetadata
- hydra.python.coder.set_meta_uses_name(m: PythonModuleMetadata, b: bool) PythonModuleMetadata
- hydra.python.coder.set_meta_uses_node(m: PythonModuleMetadata, b: bool) PythonModuleMetadata
- hydra.python.coder.set_meta_uses_nothing(m: PythonModuleMetadata, b: bool) PythonModuleMetadata
- hydra.python.coder.set_meta_uses_right(m: PythonModuleMetadata, b: bool) PythonModuleMetadata
- hydra.python.coder.set_meta_uses_type_alias(m: PythonModuleMetadata, b: bool) PythonModuleMetadata
- hydra.python.coder.set_meta_uses_type_var(m: PythonModuleMetadata, b: bool) PythonModuleMetadata
- hydra.python.coder.should_thunk_binding(g: Graph, b: Binding) bool
Determine if a binding should be thunked based on its complexity and triviality.
- hydra.python.coder.standard_import_statement(mod_name: str, symbols: Sequence[str]) ImportStatement
Generate a single from-import statement.
- hydra.python.coder.term_arity_with_primitives(graph: Graph, term: Term) int
Calculate term arity with proper primitive handling.
- hydra.python.coder.tvar_statement(name: Name) Statement
Create a TypeVar assignment statement for a type variable name.
- hydra.python.coder.type_alias_statement_for(env: PythonEnvironment, name: Name, tparams: Sequence[TypeParameter], mcomment: object, tyexpr: Expression) Statement
Version-aware type alias statement generation.
- hydra.python.coder.union_type_statements_for(env: PythonEnvironment, name: Name, tparams: Sequence[TypeParameter], mcomment: object, tyexpr: Expression, extra_stmts: Sequence[Statement]) Sequence[Statement]
Version-aware union type statement generation.
- hydra.python.coder.unsupported_expression(msg: str) Expression
Create an expression that calls hydra.overlay.python.dsl.python.unsupported(message) at runtime.
- hydra.python.coder.use_inline_type_params() bool
Legacy constant for backward compatibility; use useInlineTypeParamsFor in new code.
- hydra.python.coder.use_inline_type_params_for(version: PythonVersion) bool
Version-aware inline type parameters.
- hydra.python.coder.variant_args(ptype: Expression, tparams: Sequence[Name]) Args
Create args for variant (Node[type], Generic[tparams]).
- hydra.python.coder.variant_closed_pattern(env: PythonEnvironment, type_name: Name, field_name: Name, py_variant_name: Name, row_type: T0, is_enum: bool, var_name: Name, should_capture: bool) ClosedPattern
Create a ClosedPattern for a variant based on its characteristics.
- hydra.python.coder.wildcard_case_block(stmt: Statement) CaseBlock
Create a wildcard case block with a given body statement.
- hydra.python.coder.with_definitions(env: PythonEnvironment, defs: Sequence[Definition], body: Callable[[PythonEnvironment], T0]) T0
Execute a computation with definitions in scope.
- hydra.python.coder.with_lambda(v1: PythonEnvironment, v2: Lambda, v3: Callable[[PythonEnvironment], T0]) T0
Execute a computation with lambda context (adds lambda parameter to Graph).
- hydra.python.coder.with_let(v1: PythonEnvironment, v2: Let, v3: Callable[[PythonEnvironment], T0]) T0
Execute a computation with let context (adds let bindings to Graph).
- hydra.python.coder.with_let_inline(env: PythonEnvironment, lt: Let, body: Callable[[PythonEnvironment], T0]) T0
Execute a computation with inline let context (for walrus operators).
- hydra.python.coder.with_type_lambda(v1: PythonEnvironment, v2: TypeLambda, v3: Callable[[PythonEnvironment], T0]) T0
Execute a computation with type lambda context.
- hydra.python.coder.wrap_in_nullary_lambda(expr: Expression) Expression
Wrap a Python expression in a nullary lambda (thunk) for lazy evaluation.
- hydra.python.coder.wrap_lazy_arguments(g: Graph, name: Name, args: Sequence[Expression]) Sequence[Expression]
Wrap lazy-flagged arguments of a primitive call in nullary lambdas, per isLazy metadata (issue #391).