[pypy-commit] pypy unicode-fix: fix for isinstance and unicode
halgari
noreply at buildbot.pypy.org
Wed Oct 22 10:54:30 CEST 2014
Author: halgari
Branch: unicode-fix
Changeset: r74064:e5d9ee0be134
Date: 2014-10-21 11:16 -0600
http://bitbucket.org/pypy/pypy/changeset/e5d9ee0be134/
Log: 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