From 448076010f5d2867ff2f807600063eba7ddd40e7 Mon Sep 17 00:00:00 2001 From: Ben Steffensmeier Date: Sun, 15 Oct 2023 19:35:26 -0500 Subject: [PATCH] Revert: PyJType for java.util.Map now extends collections.abc.Mapping --- release_notes/4.2-notes.rst | 7 ------- src/main/c/Objects/pyjtype.c | 18 +----------------- src/main/java/jep/python/PyBuiltins.java | 2 -- src/test/java/jep/test/TestPyBuiltins.java | 10 ---------- src/test/python/test_maps.py | 6 ------ 5 files changed, 1 insertion(+), 42 deletions(-) diff --git a/release_notes/4.2-notes.rst b/release_notes/4.2-notes.rst index 6cf9d6af..4ccd9917 100644 --- a/release_notes/4.2-notes.rst +++ b/release_notes/4.2-notes.rst @@ -21,13 +21,6 @@ from a Java object. For more details on how to register a custom converter see `the wiki `_ or exec ``help(jep.setJavaToPythonConverter)`` in a Jep interpreter. -PyJType for java.util.Map now extends collections.abc.Mapping -************************************************************* -This allows Java Maps to be used in Python anywhere a Python mapping is -expected. Before this change Java Maps are missing functionality such as -``items()``, ``keys()``, and ``values()`` which are now automatically added by -extending ``collections.abc.Mapping``. - Additions of PyBuiltins *********************** The `PyBuiltins `_ diff --git a/src/main/c/Objects/pyjtype.c b/src/main/c/Objects/pyjtype.c index 4a78525c..6e5dff46 100644 --- a/src/main/c/Objects/pyjtype.c +++ b/src/main/c/Objects/pyjtype.c @@ -120,25 +120,9 @@ static int populateCustomTypeDict(JNIEnv *env, PyObject* fqnToPyType) pyjcollection)) { return -1; } - PyObject* collectionAbc = PyImport_ImportModule("collections.abc"); - if (!collectionAbc) { + if (!addSpecToTypeDict(env, fqnToPyType, JMAP_TYPE, &PyJMap_Spec, NULL)) { return -1; } - PyObject* mapping = PyObject_GetAttrString(collectionAbc, "Mapping"); - if (!mapping) { - Py_DECREF(collectionAbc); - return -1; - } - Py_DECREF(collectionAbc); - if (!PyType_Check(mapping)) { - Py_DECREF(mapping); - return -1; - } - if (!addSpecToTypeDict(env, fqnToPyType, JMAP_TYPE, &PyJMap_Spec, (PyTypeObject*) mapping)) { - Py_DECREF(mapping); - return -1; - } - Py_DECREF(mapping); if (!addSpecToTypeDict(env, fqnToPyType, JNUMBER_TYPE, &PyJNumber_Spec, &PyJObject_Type)) { return -1; diff --git a/src/main/java/jep/python/PyBuiltins.java b/src/main/java/jep/python/PyBuiltins.java index 0cb327d4..d585484a 100644 --- a/src/main/java/jep/python/PyBuiltins.java +++ b/src/main/java/jep/python/PyBuiltins.java @@ -46,8 +46,6 @@ public interface PyBuiltins { public PyObject dict(); - public PyObject dict(Map mapping); - public String[] dir(PyObject object); public Object eval(String expression, PyObject globals); diff --git a/src/test/java/jep/test/TestPyBuiltins.java b/src/test/java/jep/test/TestPyBuiltins.java index f3a29164..401b56c8 100644 --- a/src/test/java/jep/test/TestPyBuiltins.java +++ b/src/test/java/jep/test/TestPyBuiltins.java @@ -84,16 +84,6 @@ private boolean testDict() { failure = "dict builtin does not return an empty dict"; return false; } - Map map = new HashMap<>(); - map.put("a", 1); - map.put("b", 2); - map.put("c", 3); - dictBuiltin = builtins.dict(map); - dictGetValue = interp.getValue("{'a':1, 'b':2, 'c':3}", PyObject.class); - if (!dictBuiltin.equals(dictGetValue)){ - failure = "dict builtin does not return a dict from map"; - return false; - } return true; } diff --git a/src/test/python/test_maps.py b/src/test/python/test_maps.py index dbcec8c0..27199be0 100644 --- a/src/test/python/test_maps.py +++ b/src/test/python/test_maps.py @@ -43,12 +43,6 @@ def test_len(self): pymap = makePythonDict() self.assertEqual(len(jmap), len(pymap)) - def test_mapping(self): - jmap = makeJavaMap() - self.assertTrue(isinstance(jmap, Mapping)) - pymap = makePythonDict() - self.assertEqual(dict(jmap), pymap) - def test_del(self): jmap = makeJavaMap() pymap = makePythonDict()