Dear Jython-dev,

Recently I have been having problems with calling Java constructors from Python.

If a Java-class constructor is defined as:

public MyClass(PyObject values[], String keywords[])

Such that the constructor can take Python keyword arguments as parameters,

and it is invoked from Python like so:

x = MyClass(x=1)

the call fails with:

AttributeError: MyClass does not have attribute 'x' (or some such)

This is caused by PyReflectedConstructur.__call__, which contains the lines (lines 140-143):

        int offset = args.length;
        for (int i = 0; i < nkeywords; i++) {
            self.__setattr__(keywords[i], allArgs[i + offset]);

This code is (I assume) for the purpose of easing the creation of objects that have bean
properties. It is checked for in the regression tests.

This code breaks the constructor specified above.
The exception that one expects from specifying an unexpected keyword argument is
a TypeError.
In addition, it could be argued that the resulting behavior is not what one would expect;
I would only expect the underlying constructor to be called, I would not expect properties
to be set as well.

How do we proceed?

There are a few options:

1. Leave things as they are
2. Use a different technique such that you get a TypeError instead of an AttributeError
3. Only attempt to set known bean-properties, leave any other keyword-args alone
4. Do not attempt to set bean properties in a constructor call

Thank you for your time.


Geoffrey French