Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert: PyJType for java.util.Map now extends collections.abc.Mapping #503

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions release_notes/4.2-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ from a Java object. For more details on how to register a custom converter see
`the wiki <https://github.com/ninia/jep/wiki/Accessing-Java-Objects-in-Python#custom-conversion-functions>`_
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 <http://ninia.github.io/jep/javadoc/4.2/jep/python/PyBuiltin.html>`_
Expand Down
18 changes: 1 addition & 17 deletions src/main/c/Objects/pyjtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/jep/python/PyBuiltins.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 0 additions & 10 deletions src/test/java/jep/test/TestPyBuiltins.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,6 @@ private boolean testDict() {
failure = "dict builtin does not return an empty dict";
return false;
}
Map<String,Integer> 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;
}

Expand Down
6 changes: 0 additions & 6 deletions src/test/python/test_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down