Lists on JPython 1.1b3

Eric Jacobs x at x.x
Mon Oct 18 01:11:46 EDT 1999


I'm just trying to get started with JPython, and I'm having a little
bit of trouble with attributes of lists. (Please let me know if this
is not the best group to post about JPython in.)

>>> l = [3,2,1]
>>> l.sort()
Traceback (innermost last):
  File "<console>", line 1, in ?
java.lang.NoSuchMethodError: org/python/core/PySequence: method
__findattr__(Lja
va/lang/String;)Lorg/python/core/PyObject; not found
        at org/python/core/PyList.__findattr__
        at org/python/core/PyObject.__getattr__
        :

dir(l) and other methods of l cause the same problem.

Then, I was looking at the classes:

>>> from org.python.core import PyList, PyDictionary
>>> dir(PyList)
['toString', 'hashCode', 'sort', 'extend', 'pop', 'reverse', 'remove',
'insert',
 'index', 'count', 'append', 'initModule', '__add__', '__findattr__',
'__len__',
 '__class__']
>>> PyList.sort(l)
Traceback (innermost last):
  File "<console>", line 1, in ?
java.lang.NullPointerException
        at org/python/core/ListFunctions.__call__
        at org/python/core/PyObject.invoke
        :

java.lang.NullPointerException: java.lang.NullPointerException
>>> PyList.sort(1,2,3,4,5,6)
Traceback (innermost last):
  File "<console>", line 1, in ?
TypeError: sort(): expected 0-1 args; got 6
                            ^^^
Since PyList is a class, PyList.sort should be an unbound method and
should be taking at least one argument. This seemed sort of
suspicious. (PyList.sort() with no args crashed the same way as
the PyList.sort(l) above.)

I looked at the dictionary class and found I didn't have any
trouble getting dictionaries to work. The methods of PyDictionary
exhibited the expected behavior:

>>> PyDictionary.keys()
Traceback (innermost last):
  File "<console>", line 1, in ?
TypeError: keys(): expected 1 args; got 0
>>> {2:3, 4:5}.keys()
[4, 2]

I also noted that the methods of the non-functional list class and
the working dictionary class were considered different kinds of
methods:

>>> PyList.sort
<builtin method 'sort'>
>>> PyDictionary.keys
<java function keys at 685>

This seemed to be a bogus distinction; since JPython is an
implementation of Python in Java, shouldn't all "built-in"
functions of Python really be Java functions? In any event,
these functions called builtins weren't working. There was
at least another problem in the PyList class independent
of that, though, because:

>>> PyList.toString
<method java.lang.Object.toString of java.lang.Class instance at 692>
>>> PyList.toString([5,6,7])
Traceback (innermost last):
  File "<console>", line 1, in ?
TypeError: toString(): expected 0 args; got 1
>>> PyList.toString()
'class org.python.core.PyList'

I don't believe that is the intended effect of PyList.toString.
In PyDictionary, toString is a method of dictionary objects that
writes the dictionary out as a string.

Finally, I saw in the NEWS file that a new procedure for
implementing built in methods was being tried on list
objects:

- A new framework for looking up the methods for builtin types has
  been enabled.  This can speed up method calls by a factor of 2.
  The feature is currently experimental and has only been
  implemented for list objects, but will be implemented for other
  builtin objects for the next release.

So at least I knew something really freaky wasn't going on,
but I still am just trying to learn JPython and I lack the
technical knowledge to figure out what's going on here.

Can anyone help me fit these clues together? Any ideas?




More information about the Python-list mailing list