From: <le...@us...> - 2008-09-20 02:08:41
|
Revision: 5341 http://jython.svn.sourceforge.net/jython/?rev=5341&view=rev Author: leosoto Date: 2008-09-20 02:08:34 +0000 (Sat, 20 Sep 2008) Log Message: ----------- PyType now exposes __repr__ and __str__ as documented on <http://wiki.python.org/jython/JythonDeveloperGuide/ImplementingStrAndRepr>. This fixes #1131 Modified Paths: -------------- trunk/jython/Lib/test/test_class_jy.py trunk/jython/src/org/python/core/PyType.java Modified: trunk/jython/Lib/test/test_class_jy.py =================================================================== --- trunk/jython/Lib/test/test_class_jy.py 2008-09-18 19:37:19 UTC (rev 5340) +++ trunk/jython/Lib/test/test_class_jy.py 2008-09-20 02:08:34 UTC (rev 5341) @@ -298,7 +298,18 @@ class Bar(object): self.assertEqual(__module__, module_name) +class ClassMetaclassRepr(unittest.TestCase): + """Verifies #1131 is fixed""" + def test_repr_with_metaclass(self): + class FooMetaclass(type): + def __new__(cls, name, bases, attrs): + return super(FooMetaclass, cls).__new__(cls, name, bases, attrs) + class Foo(object): + __metaclass__ = FooMetaclass + self.assertEqual("<class '%s.Foo'>" % __name__, repr(Foo)) + + def test_main(): test_support.run_unittest(ClassGeneralTestCase, ClassNamelessModuleTestCase, @@ -307,6 +318,7 @@ IsDescendentTestCase, JavaClassNamingTestCase, ClassDefinesDunderModule, + ClassMetaclassRepr, ) Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2008-09-18 19:37:19 UTC (rev 5340) +++ trunk/jython/src/org/python/core/PyType.java 2008-09-20 02:08:34 UTC (rev 5341) @@ -1344,7 +1344,8 @@ return numSlots; } - public String toString() { + @ExposedMethod(names = {"__repr__", "__str__"}) + public String type_toString() { String kind; if (!builtin) { kind = "class"; @@ -1358,6 +1359,10 @@ return String.format("<%s '%s'>", kind, getName()); } + public String toString() { + return type_toString(); + } + /** * Raises AttributeError on type objects. The message differs from * PyObject#noAttributeError, to mimic CPython behaviour. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |