[pypy-commit] pypy default: Merged in halgari/pypy/unicode-fix (pull request #287)

fijal noreply at buildbot.pypy.org
Wed Oct 22 10:54:31 CEST 2014


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: 
Changeset: r74065:45fb4f7e5325
Date: 2014-10-22 10:54 +0200
http://bitbucket.org/pypy/pypy/changeset/45fb4f7e5325/

Log:	Merged in halgari/pypy/unicode-fix (pull request #287)

	fix for isinstance and unicode

diff --git a/rpython/rtyper/rbuiltin.py b/rpython/rtyper/rbuiltin.py
--- a/rpython/rtyper/rbuiltin.py
+++ b/rpython/rtyper/rbuiltin.py
@@ -688,10 +688,10 @@
     if hop.s_result.is_constant():
         return hop.inputconst(lltype.Bool, hop.s_result.const)
 
-    if hop.args_s[1].is_constant() and hop.args_s[1].const in (str, list):
-        if hop.args_s[0].knowntype not in (str, list):
-            raise TyperError("isinstance(x, str/list) expects x to be known"
-                             " statically to be a str/list or None")
+    if hop.args_s[1].is_constant() and hop.args_s[1].const in (str, list, unicode):
+        if hop.args_s[0].knowntype not in (str, list, unicode):
+            raise TyperError("isinstance(x, str/list/unicode) expects x to be known"
+                             " statically to be a str/list/unicode or None")
         rstrlist = hop.args_r[0]
         vstrlist = hop.inputarg(rstrlist, arg=0)
         cnone = hop.inputconst(rstrlist, None)
diff --git a/rpython/rtyper/test/test_rbuiltin.py b/rpython/rtyper/test/test_rbuiltin.py
--- a/rpython/rtyper/test/test_rbuiltin.py
+++ b/rpython/rtyper/test/test_rbuiltin.py
@@ -393,6 +393,21 @@
         res = self.interpret(f, [1])
         assert res is False
 
+    def test_isinstance_unicode(self):
+        def g():
+            pass
+        def f(i):
+            if i == 0:
+                l = u"foobar"
+            else:
+                l = None
+            g()
+            return isinstance(l, unicode)
+        res = self.interpret(f, [0])
+        assert res is True
+        res = self.interpret(f, [1])
+        assert res is False
+
     def test_instantiate(self):
         class A:
             pass


More information about the pypy-commit mailing list