List / set / dict comprehensions
Monty inlines list, set, and dict comprehensions into the surrounding code object. The user-visible behaviour follows PEP 709: inlined comprehensions, no synthetic frame in tracebacks, comprehension targets do not leak into the enclosing scope.
- A comprehension target must be a name. CPython accepts
[i for obj.x in xs]and[i for d[k] in xs]; Monty raisesSyntaxError: comprehension target must be a name, not an attribute(ornot a subscript). A comprehension’s targets live in operand-stack slots, which a store to an object cannot reach. Attribute and subscript targets work in every other unpacking position. locals()while a comprehension is running. CPython exposes the comprehension’s active targets inlocals()during the comprehension body. Monty does not implementlocals()introspection.- Generator expressions.
(x for x in iterable)parses but currently materialises to alistrather than a lazy iterator. - Maximum number of
forclauses. Monty caps a single comprehension at 255forclauses; exceeding this raisesSyntaxError: comprehension has too many nested clauses (N); maximum is 255. Per-clause operand-stack growth means real comprehensions hit a tighterSyntaxError: comprehension target + iterator count exceeds u8 depth operandwell before that point. CPython has no equivalent compile-time limit. The cap bounds compiler recursion depth on attacker-controlled source.