[Jython] Pass variable or class reference to PythonInterpreter?

Alex Martelli aleax at aleax.it
Thu Nov 7 10:28:23 EST 2002


Robert Oschler wrote:
   ...
>> value theString.  *CHANGING* it is obviously out of the question
>> (strings are immutable in Java *AND* in Python), but THAT
>> is clearly a completely different issue.
> 
> Re: String == immutable.  Sure, but other types and user classes are OK
> right?  At least that's what the tests I ran indicated.  I did discover

Sure - you can call any method on such variables, so if they have
methods that mutate them, that's OK, too.

> that a the class of a instance variable passed to the python interpreter
> via the set() method, must be public if it's going to be accessed by the
> Python Interpreter, otherwise you get a Java illegal access exception when

I didn't know that, but I'm not surprised based on the way Java
reflection works.

> Jython
> tries to reflect the class.  I would have thought private inner classes,
> 'inner' to the class whose method created the PythonInterpreter insntance,
> would have been OK but they're not.

Unfortunately, languages which rely on private &c for access or
visibility restriction are seriously hampered -- none that I know
has the equivalent of SQL's "WITH GRANT OPTION" clause; i.e. even
if class X is entitled to (whatever) regarding attribute Y or
class Z, yet X *just cannot grant the same privilege to other
classes yet*, such as, those used in reflection/introspection.

I consider this a serious design defect of languages such as Java
and C++.  Python, of course, finesses the issue by eschewing all
use of such access/visibility restrictions, but I know of no
general purpose programming language whose access/visibility
control is really _good_ (e.g., AT LEAST the equal of what you can
achieve in SQL with views, GRANT, and WITH GRANT OPTION) -- thus,
inevitably, such control ends up getting in the way.

You CAN ask Jython to NOT respect Java's 'privacy' settings with
some option (I forget the details, as I've never had to use this
option myself), which I think is meant to let you write testing
code in Jython that's able to get at all aspects of the classes
it's testing.  But when you do that there's no selectivity -- it's
like a steamroller flattening all access to 'public' or thereabouts.


Alex




More information about the Python-list mailing list