From d6f315a2cd52b9e968c1f0e84054d0f6a3583397 Mon Sep 17 00:00:00 2001 From: Caleb Aikens Date: Wed, 29 Nov 2023 10:17:46 -0500 Subject: [PATCH] Revert "JSObjectProxy now implements the dict "or" operation" --- include/JSObjectProxy.hh | 23 ---------- src/JSObjectProxy.cc | 53 ------------------------ src/modules/pythonmonkey/pythonmonkey.cc | 1 - tests/python/test_dicts_lists.py | 47 +-------------------- 4 files changed, 1 insertion(+), 123 deletions(-) diff --git a/include/JSObjectProxy.hh b/include/JSObjectProxy.hh index f65a4ee6..e22e146a 100644 --- a/include/JSObjectProxy.hh +++ b/include/JSObjectProxy.hh @@ -129,24 +129,6 @@ public: * @return the string representation (a PyUnicodeObject) on success, NULL on failure */ static PyObject *JSObjectProxy_repr(JSObjectProxy *self); - - /** - * @brief Set union method - * - * @param self - The JSObjectProxy - * @param other - The other PyObject to be or'd, expected to be dict or JSObjectProxy - * @return PyObject* The resulting new dict - */ - static PyObject *JSObjectProxy_or(JSObjectProxy *self, PyObject *other); - - /** - * @brief Set union method, in place - * - * @param self - The JSObjectProxy - * @param other - The other PyObject to be or'd, expected to be dict or JSObjectProxy - * @return PyObject* The resulting new dict, must be same object as self - */ - static PyObject *JSObjectProxy_ior(JSObjectProxy *self, PyObject *other); }; @@ -164,11 +146,6 @@ static PySequenceMethods JSObjectProxy_sequence_methods = { .sq_contains = (objobjproc)JSObjectProxyMethodDefinitions::JSObjectProxy_contains }; -static PyNumberMethods JSObjectProxy_number_methods = { - .nb_or = (binaryfunc)JSObjectProxyMethodDefinitions::JSObjectProxy_or, - .nb_inplace_or = (binaryfunc)JSObjectProxyMethodDefinitions::JSObjectProxy_ior -}; - /** * @brief Struct for the JSObjectProxyType, used by all JSObjectProxy objects */ diff --git a/src/JSObjectProxy.cc b/src/JSObjectProxy.cc index 3fe56d4a..06965285 100644 --- a/src/JSObjectProxy.cc +++ b/src/JSObjectProxy.cc @@ -21,8 +21,6 @@ #include -#include - JSContext *GLOBAL_CX; /**< pointer to PythonMonkey's JSContext */ bool keyToId(PyObject *key, JS::MutableHandleId idp) { @@ -260,54 +258,3 @@ PyObject *JSObjectProxyMethodDefinitions::JSObjectProxy_repr(JSObjectProxy *self PyDict_DelItem(tsDict, cyclicKey); return str; } - -PyObject *JSObjectProxyMethodDefinitions::JSObjectProxy_or(JSObjectProxy *self, PyObject *other) { - if (!PyDict_Check(self) || !PyDict_Check(other)) { - Py_RETURN_NOTIMPLEMENTED; - } - - if (!PyObject_TypeCheck(self, &JSObjectProxyType) && PyObject_TypeCheck(other, &JSObjectProxyType)) { - return PyDict_Type.tp_as_number->nb_or((PyObject *)&(self->dict), other); - } else { - JS::Rooted> args(GLOBAL_CX); - args[0].setObjectOrNull(JS_NewPlainObject(GLOBAL_CX)); - args[1].setObjectOrNull(self->jsObject); // this is null is left operand is real dict - JS::RootedValue jValueOther(GLOBAL_CX, jsTypeFactory(GLOBAL_CX, other)); - args[2].setObject(jValueOther.toObject()); - - JS::RootedObject *global = new JS::RootedObject(GLOBAL_CX, JS::GetNonCCWObjectGlobal(self->jsObject)); - - // call Object.assign - JS::RootedValue Object(GLOBAL_CX); - JS_GetProperty(GLOBAL_CX, *global, "Object", &Object); - - JS::RootedObject rootedObject(GLOBAL_CX, Object.toObjectOrNull()); - JS::RootedValue ret(GLOBAL_CX); - - if (!JS_CallFunctionName(GLOBAL_CX, rootedObject, "assign", args, &ret)) return NULL; - return pyTypeFactory(GLOBAL_CX, global, &ret)->getPyObject(); - } -} - -PyObject *JSObjectProxyMethodDefinitions::JSObjectProxy_ior(JSObjectProxy *self, PyObject *other) { - if (!PyDict_Check(self) || !PyDict_Check(other)) { - Py_RETURN_NOTIMPLEMENTED; - } - - JS::Rooted> args(GLOBAL_CX); - args[0].setObjectOrNull(self->jsObject); - JS::RootedValue jValueOther(GLOBAL_CX, jsTypeFactory(GLOBAL_CX, other)); - args[1].setObject(jValueOther.toObject()); - - JS::RootedObject *global = new JS::RootedObject(GLOBAL_CX, JS::GetNonCCWObjectGlobal(self->jsObject)); - - // call Object.assign - JS::RootedValue Object(GLOBAL_CX); - JS_GetProperty(GLOBAL_CX, *global, "Object", &Object); - - JS::RootedObject rootedObject(GLOBAL_CX, Object.toObjectOrNull()); - JS::RootedValue ret(GLOBAL_CX); - if (!JS_CallFunctionName(GLOBAL_CX, rootedObject, "assign", args, &ret)) return NULL; - Py_INCREF(self); - return (PyObject *)self; -} diff --git a/src/modules/pythonmonkey/pythonmonkey.cc b/src/modules/pythonmonkey/pythonmonkey.cc index c673ef73..56cf23e1 100644 --- a/src/modules/pythonmonkey/pythonmonkey.cc +++ b/src/modules/pythonmonkey/pythonmonkey.cc @@ -74,7 +74,6 @@ PyTypeObject JSObjectProxyType = { .tp_basicsize = sizeof(JSObjectProxy), .tp_dealloc = (destructor)JSObjectProxyMethodDefinitions::JSObjectProxy_dealloc, .tp_repr = (reprfunc)JSObjectProxyMethodDefinitions::JSObjectProxy_repr, - .tp_as_number = &JSObjectProxy_number_methods, .tp_as_sequence = &JSObjectProxy_sequence_methods, .tp_as_mapping = &JSObjectProxy_mapping_methods, .tp_getattro = (getattrofunc)JSObjectProxyMethodDefinitions::JSObjectProxy_get, diff --git a/tests/python/test_dicts_lists.py b/tests/python/test_dicts_lists.py index f009b068..79c620c5 100644 --- a/tests/python/test_dicts_lists.py +++ b/tests/python/test_dicts_lists.py @@ -137,49 +137,4 @@ def test_eval_objects_jsproxy_does_not_contain(): def test_eval_objects_jsproxy_does_not_contain_value(): a = pm.eval("({'c':5})") - assert not(5 in a) - -def test_eval_objects_jsproxy_or(): - a = pm.eval("({'c':5})") - b = pm.eval("({'d':6})") - c = a | b - assert a == {'c': 5.0} - assert c == {'c': 5.0, 'd': 6.0} - assert b == {'d': 6.0} - -def test_eval_objects_jsproxy_or_true_dict_right(): - a = pm.eval("({'c':5})") - b = {'d': 6.0} - c = a | b - assert a == {'c': 5.0} - assert c == {'c': 5.0, 'd': 6.0} - assert b == {'d': 6.0} - -def test_eval_objects_jsproxy_or_true_dict_left(): - a = {'c':5} - b = pm.eval("({'d':6})") - c = a | b - assert a == {'c': 5.0} - assert c == {'c': 5.0, 'd': 6.0} - assert b == {'d': 6.0} - -def test_eval_objects_jsproxy_inplace_or(): - a = pm.eval("({'c':5})") - b = pm.eval("({'d':6})") - a |= b - assert a == {'c': 5.0, 'd': 6.0} - assert b == {'d': 6.0} - -def test_eval_objects_jsproxy_inplace_or_true_dict_right(): - a = pm.eval("({'c':5})") - b = {'d':6.0} - a |= b - assert a == {'c': 5.0, 'd': 6.0} - assert b == {'d': 6.0} - -def test_eval_objects_jsproxy_inplace_or_true_dict_left(): - a = {'c':5.0} - b = pm.eval("({'d':6})") - a |= b - assert a == {'c': 5.0, 'd': 6.0} - assert b == {'d': 6.0} \ No newline at end of file + assert not(5 in a) \ No newline at end of file