TYPED CONVERSIONS

Containers and records

Use small, fixed local containers and immutable records. Their contents and structure must fit the forms below.

Mode: typed conversion. Select Transpile → Typed, then click Transpile, or use the default CLI/API request. For runtime strings, shared containers, classes, and closures, see Runtime value conversions.

Fixed local containers

Assign a container once, directly in a function body, with 1–64 elements. Do not resize it, reassign it, alias it through another variable, pass it to a function, or return it.

Lists and tuples

def pick() -> int:
    values = [10, 20, 30]
    return values[-1]

pick() returns 30.

Use elements of one type: bool, int, float, or str. An index must be a direct integer literal within bounds; negative indices are supported. You can also iterate over the elements in order.

Sets and membership

def is_priority(value: int) -> bool:
    priorities = {1, 4, 9}
    return value in priorities

is_priority(4) returns True; is_priority(2) returns False.

Use unique literal int, finite float, or bool elements, all of one type. Check membership with in or not in, using the local set name. The searched value must have that same type.

Empty sets, strings in sets, computed elements, duplicate elements, set methods, set indexing, and set iteration are unsupported. Use a list or tuple when you need iteration or indexing.

Dictionaries

def lookup() -> int:
    values = {'low': 1, 'high': 2}
    return values['high']

lookup() returns 2.

Keys must be unique literal integers or strings of one type. Values must also use one supported scalar type. Lookup needs a literal key present in the dictionary. Iteration yields keys in insertion order.

If a container is rejected

Check for empty, oversized, mixed-type or nested contents; computed indices; element changes; methods; or a container used outside its local function. Comprehensions and generator expressions are unsupported in typed conversion. Use runtime list comprehensions when building a list from supported iterables. Flat scalar assignment such as a, b = 1, 2 is supported separately; unpacking an arbitrary container variable is not.

Simple immutable records

class Point:
    x: int
    y: int

    def __init__(self, x: int, y: int) -> None:
        self.x = x
        self.y = y

def sum_point(left: int, right: int) -> int:
    point = Point(left, right)
    return point.x + point.y

sum_point(3, 4) returns 7.

Define 1–64 annotated int, float, or bool fields, followed by one initializer. Each initializer parameter must match a field and be assigned directly to it. Create a fresh local instance with positional arguments, then read its fields.

Record parameters and returns

Annotate a parameter or result with the record's class name. This complete example constructs a point in one function, returns it to the caller, and passes it to another function.

class Point:
    x: int
    y: int

    def __init__(self, x: int, y: int) -> None:
        self.x = x
        self.y = y

def make_point(x: int, y: int) -> Point:
    point = Point(x, y)
    return point

def sum_point(point: Point) -> int:
    return point.x + point.y

def keep_point(point: Point) -> Point:
    return point

def total(x: int, y: int) -> int:
    point = make_point(x, y)
    return sum_point(keep_point(point))

total(3, 4) returns 7; total(-3, 3) returns 0. A function can also return another record-returning call, such as return keep_point(make_point(x, y)).

OperationSupported form
Declare a typeDefine the class before the module's functions. Use its unquoted name: point: Point and -> Point.
Create or receive a valueAssign a constructor, factory result or existing record to a fresh local directly in the function body; an initialized exact class annotation is optional. A constructor may also be used directly as a return value or positional function argument.
Pass a valueUse exact positional arguments. Pass a record constructor, local, parameter, or record-returning call to a parameter annotated with that same class.
Return a valueReturn a constructor, local, parameter, or record-returning call. Every reachable exit must return the declared type; branches can construct different values of that same type.
Read a fieldUse a local, parameter, constructor or factory result. Nested paths and fixed collection elements are also supported, such as make_particle().position.x and points[0].x.

Construct records in calls and returns

Use return Point(x, y) when a function creates its result, or pass a constructor directly to a positional record parameter. The following complete example reflects a point across an axis and measures its squared distance from the origin.

class Point:
    x: int
    y: int

    def __init__(self, x: int, y: int) -> None:
        self.x = x
        self.y = y

def reflect(point: Point, across_y: bool) -> Point:
    if across_y:
        return Point(-point.x, point.y)
    return Point(point.x, -point.y)

def squared_norm(point: Point) -> int:
    return point.x * point.x + point.y * point.y

def reflected_energy(
    x: int, y: int, across_y: bool
) -> int:
    return squared_norm(reflect(Point(x, y), across_y))

reflected_energy(3, 4, True) returns 25. With across_y=True, the reflected point is (-3, 4); with False, it is (3, -4). Both have the same squared distance. Inputs and intermediate results must fit the documented signed 64-bit arithmetic bounds.

Each constructor argument is evaluated once, from left to right. The generated C initializes an automatic struct before passing or returning its value. A constructor inside a branch runs only when that branch is taken. No heap allocation, cleanup call, or pointer to expired local storage is introduced.

The receiving parameter or return annotation must name the exact declaring class. An imported alias refers to that same type; another class with identical fields does not. Constructors accept the exact declared scalar or nested record field types, without implicit conversions between int, float, and bool.

What the generated C does

Each record becomes a C struct. Parameters and returns copy its fields, including nested records, by value, so no pointer to a completed function's local storage escapes and no allocation or free is needed. Typed source cannot mutate records or inspect object identity. Within that accepted subset, value copies preserve the observable field values of the Python program.

Record classes have distinct types even when their fields match. A Point cannot be passed where another class is declared. The same declarations are available to C callers through separate C module exports.

Record limits

Do not change fields, rebind a record parameter/local, or reassign an existing record name. Fresh local aliases such as other = point are accepted as immutable value copies. Identity checks, truth tests, equality on whole records, dynamic attributes, nested captures, and fields containing strings or containers are unsupported. Nested immutable record fields and fixed local record lists/tuples are supported; see Structured records for complete examples, indexing rules and layout limits.

Record-boundary functions use positional calls without defaults, variadic arguments, or keyword-only parameters. Record constructors and calls that pass or return records inside and/or or chained comparisons are unsupported; use an explicit if branch. Constructors also require exact positional arguments. Read fields through a local, parameter, constructor or factory result, including nested paths such as make_particle().position.x. Quoted/forward record annotations, inheritance, decorators, and methods beyond the exact initializer are also unsupported.

Python module scope: directly import a record class from its defining supplied module, with an optional as alias. Functions in other supplied modules can construct, receive, forward, and return that same nominal type. A companion module may contain only record definitions. See the complete three-module geometry example. Separate generated C callers use the same exported struct interface.