[pypy-svn] r14750 - in pypy/dist/pypy: rpython rpython/test translator/goal
pedronis at codespeak.net
pedronis at codespeak.net
Mon Jul 18 21:25:35 CEST 2005
Author: pedronis
Date: Mon Jul 18 21:25:32 2005
New Revision: 14750
Modified:
pypy/dist/pypy/rpython/rbuiltin.py
pypy/dist/pypy/rpython/test/test_rbuiltin.py
pypy/dist/pypy/translator/goal/ISSUES.txt
Log:
isinstance(<lst>, list)
Modified: pypy/dist/pypy/rpython/rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/rbuiltin.py (original)
+++ pypy/dist/pypy/rpython/rbuiltin.py Mon Jul 18 21:25:32 2005
@@ -120,6 +120,14 @@
c = hop.inputconst(pyobj_repr, isinstance)
v = hop.genop('simple_call', [c, v_obj, v_typ], resulttype = pyobj_repr)
return hop.llops.convertvar(v, pyobj_repr, bool_repr)
+
+ if hop.args_s[1].is_constant() and hop.args_s[1].const == list:
+ if hop.args_s[0].knowntype != list:
+ raise TyperError("isinstance(x, list) expects x to be known statically to be a list or None")
+ rlist = hop.args_r[0]
+ vlist = hop.inputarg(rlist, arg=0)
+ cnone = hop.inputconst(rlist, None)
+ return hop.genop('ptr_ne', [vlist, cnone], resulttype=lltype.Bool)
instance_repr = rclass.getinstancerepr(hop.rtyper, None)
class_repr = rclass.get_type_repr(hop.rtyper)
Modified: pypy/dist/pypy/rpython/test/test_rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rbuiltin.py (original)
+++ pypy/dist/pypy/rpython/test/test_rbuiltin.py Mon Jul 18 21:25:32 2005
@@ -179,3 +179,15 @@
return isinstance(b, B)
res = interpret(f, [])
assert res is True
+
+def test_isinstance_list():
+ def f(i):
+ if i == 0:
+ l = []
+ else:
+ l = None
+ return isinstance(l, list)
+ res = interpret(f, [0])
+ assert res is True
+ res = interpret(f, [1])
+ assert res is False
Modified: pypy/dist/pypy/translator/goal/ISSUES.txt
==============================================================================
--- pypy/dist/pypy/translator/goal/ISSUES.txt (original)
+++ pypy/dist/pypy/translator/goal/ISSUES.txt Mon Jul 18 21:25:32 2005
@@ -11,9 +11,6 @@
* we need a call_args similar to simple_call (doing redispatching)
on MethodOfFrozenPBCRepr etc
- * implementation for isinstance(x,list) makes sense only if x is a list, then needs
- to check that x is not None
-
* the PBCReprs generally lack a convert_from_to() to convert from a small PBC
set to a larger one.
More information about the Pypy-commit
mailing list