Issue1748817

classification
Title: Python __repr__ added to Java class is ignored by repr()
Type: Severity: normal
Components: Core Versions:
Milestone:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: cgroves, lieske
Priority: normal Keywords:

Created on 2007-07-06.01:29:31 by lieske, last changed 2007-07-30.02:34:05 by cgroves.

Messages
msg1706 (view) Author: Jay Lieske (lieske) Date: 2007-07-06.01:29:31
For a Python-defined class, it's possible to add a __repr__ method to the class which is invoked by the repr() built-in function.

That does not work for a Java-defined class.  Though one can define a __repr__ method, the method is not called by repr().

Example:

>>> import java.awt.geom
>>> e = java.awt.geom.Ellipse2D.Double(3, 4, 5, 6)
>>> e
java.awt.geom.Ellipse2D$Double@eb8007
### that is the standard Java Object.toString() of the instance

### Define a repr function for Ellipse2D
>>> def reprEllipse2D(self):
...     return "Ellipse2D(%g,%g,%g,%g)" % (self.x, self.y, self.width, self.height)

>>> reprEllipse2D(e)
'Ellipse2D(3,4,5,6)'


>>> java.awt.geom.Ellipse2D.Double.__repr__ = reprEllipse2D
>>> e
java.awt.geom.Ellipse2D$Double@eb8007
>>> repr(e)
'java.awt.geom.Ellipse2D$Double@eb8007'
### Jython is still using Object.toString()
>>> e.__repr__()
'Ellipse2D(3,4,5,6)'
### even though the method is accessible
msg1707 (view) Author: Charlie Groves (cgroves) Date: 2007-07-30.02:34:05
This is fixed in the 2.3 branch in r3364.
History
Date User Action Args
2007-07-06 01:29:31lieskecreate