diff --git a/src/obj.h b/src/obj.h index 7dce1a56..4ce5b395 100644 --- a/src/obj.h +++ b/src/obj.h @@ -56,6 +56,13 @@ struct BoundMethod { PyObject* self; PyObject* func; BoundMethod(PyObject* self, PyObject* func) : self(self), func(func) {} + + bool operator==(const BoundMethod& rhs) const noexcept { + return self == rhs.self && func == rhs.func; + } + bool operator!=(const BoundMethod& rhs) const noexcept { + return self != rhs.self || func != rhs.func; + } }; struct Range { diff --git a/src/pocketpy.h b/src/pocketpy.h index 0bfa339b..aee2d6c1 100644 --- a/src/pocketpy.h +++ b/src/pocketpy.h @@ -972,6 +972,18 @@ inline void VM::post_init(){ return CAST(BoundMethod&, args[0]).func; })); + vm->bind_method<1>(_t(tp_bound_method), "__eq__", [](VM* vm, ArgsView args){ + if(!is_non_tagged_type(args[1], vm->tp_bound_method)) return vm->False; + bool ok = _CAST(BoundMethod&, args[0]) == _CAST(BoundMethod&, args[1]); + return VAR(ok); + }); + + vm->bind_method<1>(_t(tp_bound_method), "__ne__", [](VM* vm, ArgsView args){ + if(!is_non_tagged_type(args[1], vm->tp_bound_method)) return vm->True; + bool ok = _CAST(BoundMethod&, args[0]) != _CAST(BoundMethod&, args[1]); + return VAR(ok); + }); + _t(tp_slice)->attr().set("start", property([](VM* vm, ArgsView args){ return CAST(Slice&, args[0]).start; })); diff --git a/tests/99_bugs.py b/tests/99_bugs.py index 4c1eda34..4eeb827a 100644 --- a/tests/99_bugs.py +++ b/tests/99_bugs.py @@ -11,4 +11,11 @@ def f(x): return 1 assert f(2) == 1 -assert f(0) == None \ No newline at end of file +assert f(0) == None + +a = [1, 2] +b = [3, 4] +assert a.append == a.append +assert a.append is not a.append +assert a.append is not b.append +assert a.append != b.append \ No newline at end of file