bcdev / jpy

A bi-directional Python-Java bridge used to embed Java in CPython or the other way round.
Apache License 2.0
187 stars 37 forks source link

PyDictWrapper keys/values broken in Python 3 #160

Open devinrsmith opened 5 years ago

devinrsmith commented 5 years ago

Calling PyDictWrapper#keys or PyDictWrapper#values in the context of Python 3 causes

RuntimeError: java.lang.ClassCastException: Can not convert non-list type to a list!
    at org.jpy.PyObject.asList(PyObject.java:256)
    at org.jpy.PyDictWrapper.keySet(PyDictWrapper.java:112)

Dictionary keys and values are views in Python 3.

https://blog.labix.org/2008/06/27/watch-out-for-listdictkeys-in-python-3

devinrsmith commented 5 years ago

Also, has_key is no longer a method on dict in Python 3. https://portingguide.readthedocs.io/en/latest/dicts.html

devinrsmith commented 5 years ago

(Will be submitting MR soon)