Issue1131

classification
Title: repr not 100% CPython compliant
Type: Severity: normal
Components: Versions:
Milestone:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: brosner, leosoto
Priority: Keywords:

Created on 2008-09-13.22:37:48 by brosner, last changed 2008-09-20.02:09:40 by leosoto.

Files
File name Uploaded Description Edit Remove
1131_repr_metaclass_test.diff brosner, 2008-09-13.22:38:44
Messages
msg3545 (view) Author: Brian Rosner (brosner) Date: 2008-09-13.22:37:48
It appears the repr implementation is not 100% compliant with CPython.

brian@brosner-osx master [~/Development/jython]
$ jython
Jython 2.5a3+ (unknown:exported, Sep 13 2008, 16:25:22) 
[Java HotSpot(TM) Server VM (Sun Microsystems Inc.)] on java1.6.0_03-p3
Type "help", "copyright", "credits" or "license" for more information.
>>> class FormMetaclass(type):
...     def __new__(cls, name, bases, attrs):
...         return super(FormMetaclass, cls).__new__(cls, name, bases, 
attrs)
... 
>>> class Form(object):
...     __metaclass__ = FormMetaclass
... 
>>> Form
<__main__.FormMetaclass object at 1>
>>>

brian@brosner-osx [~]
$ python
Python 2.5.1 (r251:54863, Feb  4 2008, 21:48:13) 
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> class FormMetaclass(type):
...     def __new__(cls, name, bases, attrs):
...         return super(FormMetaclass, cls).__new__(cls, name, bases, 
attrs)
... 
>>> class Form(object):
...     __metaclass__ = FormMetaclass
... 
>>> Form
<class '__main__.Form'>
>>>

It appears that Jython uses type() in this case.
msg3546 (view) Author: Brian Rosner (brosner) Date: 2008-09-13.22:38:44
Here is a test case to the best of my ability.
msg3565 (view) Author: Leonardo Soto (leosoto) Date: 2008-09-14.00:51:23
The cause here is PyTypeDerived#__repr__ looking up for the  "__repr__"
entry on its type and finding the one exposed by PyObject.

I think we will have to check if the type that exposed __repr__ is down
in the type hierarchy or not. In the later case, we should call super()
instead of the exposed __repr__().  Another possibility would be to
actually expose __repr__ on PyType, but that would mean that we should
do the same with every type implementing toString().
msg3598 (view) Author: Leonardo Soto (leosoto) Date: 2008-09-15.03:34:46
Quick note: my first idea wasn't that good: too complicated and just
hides the real problem. 

So we should just expose __repr__ and __str__ on PyType, following
what's documented on
http://wiki.python.org/jython/JythonDeveloperGuide/ImplementingStrAndRepr
msg3608 (view) Author: Leonardo Soto (leosoto) Date: 2008-09-20.02:09:39
Fixed on r5341
History
Date User Action Args
2008-09-20 02:09:40leosotosetstatus: open -> closed
resolution: fixed
messages: + msg3608
2008-09-15 03:34:47leosotosetmessages: + msg3598
2008-09-14 00:51:24leosotosetnosy: + leosoto
messages: + msg3565
2008-09-13 22:38:45brosnersetfiles: + 1131_repr_metaclass_test.diff
messages: + msg3546
2008-09-13 22:37:48brosnercreate