feat: random generators, frozenset and __hash__/__iter__/__getitem__/__contains__ in Ren'Py python
CI / frontend (push) Failing after 18s
CI / backend (push) Failing after 35s

renpy.random/random get choices, sample, randrange and Random(seed); frozenset, iter and hash
are builtins. User classes may define __hash__ (dict keys), __iter__, __getitem__ and
__contains__; the converter accepts them instead of rejecting the whole class, which
removes the Perk/Skill/Status wall in SaintlyCorruption.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
mrleo1nidandClaude Sonnet 5.5 committed 2026-10-26 02:55:44 +03:00
1 parent f9eb5c1212
commit e1c596288e
8 files changed
+165 -18

No files matched your search

+12 -1
View File
@@ -14,7 +14,7 @@ const ir = (name) => JSON.parse(readFileSync(new URL(`./fixtures/${name}.ir.json
function runtime() {
const store = Object.create(null);
const builtins = {
any: (xs) => xs.some(Boolean), range: (n) => Array.from({ length: n }, (_, i) => i), max: Math.max, int: Number, str: pyStr, list: (xs = []) => [...xs],
any: (xs) => xs.some(Boolean), len: (x) => (x.map ? x.map.size : x.length), range: (n) => Array.from({ length: n }, (_, i) => i), max: Math.max, int: Number, str: pyStr, list: (xs = []) => [...xs],
};
const scope = {
get: (n) => (n in store ? store[n] : builtins[n]),
@@ -110,3 +110,14 @@ test("lookups stay lenient outside try, uncaught exceptions are explicit errors"
assert.equal(py.strict, 0);
void store;
});
test("__hash__, __iter__, __getitem__ and __contains__ work on user classes", () => {
const { py, store } = runtime();
py.exec(ir("dunders"));
assert.equal(store.result_size, 1);
assert.equal(store.result_value, 2);
assert.deepEqual(store.result_loop, [6, 8, 10]);
assert.equal(store.result_item, 4);
assert.equal(store.result_in, true);
assert.equal(store.result_out, false);
});