Title: toString of java.lang.Class raises TypeError
Type: Severity: normal
Components: Versions:
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: pekka.klarck, pjenvey, yanne
Priority: Keywords:

Created on 2010-02-25.04:16:10 by yanne, last changed 2010-04-14.00:59:19 by pjenvey.

msg5554 (view) Author: Janne Härkönen (yanne) Date: 2010-02-25.04:16:09
Jython 2.5.1 (Release_2_5_1:6813, Sep 26 2009, 13:47:54) 
[Java HotSpot(TM) Server VM (Sun Microsystems Inc.)] on java1.6.0_15
Type "help", "copyright", "credits" or "license" for more information.
>>> from java.lang import String        
>>> String('').getClass().toString()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: toString(): expected 1 args; got 0
msg5619 (view) Author: Pekka Klärck (pekka.klarck) Date: 2010-04-02.09:38:27
The same problem appears also with Jython 2.2, but on Java code you can do myObject.getClass().toString() without problems.
msg5655 (view) Author: Philip Jenvey (pjenvey) Date: 2010-04-11.00:36:50
This is a tough one, the problem is that the toString attribute on the instance of the String type here is really an unbound method for the String.toString method.

That's why it expects an argument, it expects to be called as a bound method on a String instance. Just like calling str.upper() expects a str instance argument

What would have to happen is the method would somehow have to work both ways for methods implemented on the Class type. Maybe this is doable, I'm not sure, but reflected methods have a lot of tricky logic already
msg5697 (view) Author: Philip Jenvey (pjenvey) Date: 2010-04-14.00:59:19
this is actually a duplicate of #1002
Date User Action Args
2010-04-14 00:59:19pjenveysetstatus: open -> closed
resolution: duplicate
messages: + msg5697
2010-04-11 00:36:51pjenveysetnosy: + pjenvey
messages: + msg5655
2010-04-02 09:38:27pekka.klarcksetmessages: + msg5619
2010-04-02 09:28:00pekka.klarcksetnosy: + pekka.klarck
2010-02-25 04:16:10yannecreate