From ed9273c40cd0fdf853db6ac1fdfa65a662796512 Mon Sep 17 00:00:00 2001 From: AN Long Date: Mon, 2 Mar 2026 22:36:12 +0900 Subject: [PATCH] py: fix bound __index__ --- py/method.go | 5 +++++ py/tests/int.py | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/py/method.go b/py/method.go index 438ad5f4..04a36351 100644 --- a/py/method.go +++ b/py/method.go @@ -192,6 +192,11 @@ func newBoundMethod(name string, fn interface{}) (Object, error) { m.method = func(_ Object) (Object, error) { return f() } + // M__index__() (Int, error) + case func() (Int, error): + m.method = func(_ Object) (Object, error) { + return f() + } // M__add__(other Object) (Object, error) case func(Object) (Object, error): m.method = func(_ Object, other Object) (Object, error) { diff --git a/py/tests/int.py b/py/tests/int.py index 79356b3c..f7a98706 100644 --- a/py/tests/int.py +++ b/py/tests/int.py @@ -24,6 +24,10 @@ assert repr(1000000000000000000000000000000) == "1000000000000000000000000000000" assert repr(-1000000000000000000000000000000) == "-1000000000000000000000000000000" +doc="index" +assert True.__index__() == 1 +assert False.__index__() == 0 + doc="test overflow" assert int("1000000000000000000") == 10**18 assert int("-1000000000000000000") == -(10**18)