[pypy-commit] pypy default: (cfbolz, arigo): finally finally support str(cls)

cfbolz noreply at buildbot.pypy.org
Thu Aug 13 13:33:39 CEST 2015


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: 
Changeset: r78958:0822afc04fdd
Date: 2015-08-13 13:33 +0200
http://bitbucket.org/pypy/pypy/changeset/0822afc04fdd/

Log:	(cfbolz, arigo): finally finally support str(cls)

diff --git a/rpython/rtyper/rpbc.py b/rpython/rtyper/rpbc.py
--- a/rpython/rtyper/rpbc.py
+++ b/rpython/rtyper/rpbc.py
@@ -750,6 +750,10 @@
     def get_ll_eq_function(self):
         return None
 
+    def ll_str(self, ptr):
+        cls = lltype.cast_pointer(CLASSTYPE, ptr)
+        return cls.name
+
 
 def ll_cls_hash(cls):
     if not cls:
diff --git a/rpython/rtyper/test/test_rpbc.py b/rpython/rtyper/test/test_rpbc.py
--- a/rpython/rtyper/test/test_rpbc.py
+++ b/rpython/rtyper/test/test_rpbc.py
@@ -1656,6 +1656,20 @@
         res = self.interpret(g, [2])
         assert self.ll_to_string(res) == "ASub"
 
+    def test_str_class(self):
+        class Base(object): pass
+        class ASub(Base): pass
+        def g(n):
+            if n == 1:
+                x = Base()
+            else:
+                x = ASub()
+            return str(x.__class__)
+        res = self.interpret(g, [1])
+        assert self.ll_to_string(res) == "Base"
+        res = self.interpret(g, [2])
+        assert self.ll_to_string(res) == "ASub"
+
     def test_bug_callfamily(self):
         def cb1():
             xxx    # never actually called


More information about the pypy-commit mailing list