CONVERSION REFERENCE
Use small, fixed local containers and simple records. Their contents and structure must fit the forms below.
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.
def pick() -> int:
values = [10, 20, 30]
return values[-1]
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.
def is_priority(value: int) -> bool:
priorities = {1, 4, 9}
return value in priorities
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.
def lookup() -> int:
values = {'low': 1, 'high': 2}
return values['high']
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.
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. Flat scalar assignment such as a, b = 1, 2 is supported separately; unpacking an arbitrary container variable is not.
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
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.
Do not change fields after creation, add other methods, inherit from another class, use decorators or string fields, or copy, pass, or return the record. Importing records from another module and storing records in containers are unsupported.