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

+16
View File
@@ -73,3 +73,19 @@ test("an animated preview discarded before its first timer does not keep renderi
assert.equal(rendered, 1);
} finally { engine.destroy(); }
});
test("random generators: choices, sample, seeded Random and frozenset", () => {
const { engine } = makeEngine(runtime());
try {
engine.newStore();
const { renpy, frozenset } = engine.builtins;
assert.deepEqual(frozenset([1, 2, 2, 3]), [1, 2, 3]);
const picked = renpy.random.choices(["a", "b"], { __kw: { weights: [0, 1], k: 5 } });
assert.deepEqual(picked, ["b", "b", "b", "b", "b"]);
const sample = renpy.random.sample([1, 2, 3, 4], 3);
assert.equal(new Set(sample).size, 3);
const first = renpy.random.Random("seed"), second = renpy.random.Random("seed");
assert.deepEqual([first.randint(1, 1000), first.randint(1, 1000)], [second.randint(1, 1000), second.randint(1, 1000)]);
assert.ok(renpy.random.randrange(0, 10, 5) % 5 === 0);
} finally { engine.destroy(); }
});