[pypy-svn] r17434 - in pypy/dist/pypy: annotation translator/test
pedronis at codespeak.net
pedronis at codespeak.net
Sat Sep 10 00:30:14 CEST 2005
Author: pedronis
Date: Sat Sep 10 00:30:12 2005
New Revision: 17434
Modified:
pypy/dist/pypy/annotation/unaryop.py
pypy/dist/pypy/translator/test/test_annrpython.py
Log:
the old ordering could provoke contains assert failures
Modified: pypy/dist/pypy/annotation/unaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/unaryop.py (original)
+++ pypy/dist/pypy/annotation/unaryop.py Sat Sep 10 00:30:12 2005
@@ -56,13 +56,13 @@
return r
def issubtype(obj, s_cls):
- if obj.is_constant() and s_cls.is_constant():
- return immutablevalue(issubclass(obj.const, s_cls.const))
if hasattr(obj, 'is_type_of'):
vars = obj.is_type_of
annotator = getbookkeeper().annotator
return builtin.builtin_isinstance(annotator.binding(vars[0]),
s_cls, vars)
+ if obj.is_constant() and s_cls.is_constant():
+ return immutablevalue(issubclass(obj.const, s_cls.const))
return SomeBool()
def len(obj):
Modified: pypy/dist/pypy/translator/test/test_annrpython.py
==============================================================================
--- pypy/dist/pypy/translator/test/test_annrpython.py (original)
+++ pypy/dist/pypy/translator/test/test_annrpython.py Sat Sep 10 00:30:12 2005
@@ -1558,6 +1558,44 @@
assert s.knowntype == bool
assert not s.is_constant()
+ def test_issubtype_and_const(self):
+ class A(object):
+ pass
+ class B(object):
+ pass
+ class C(A):
+ pass
+ b = B()
+ c = C()
+ def g(f):
+ if f == 1:
+ x = b
+ elif f == 2:
+ x = c
+ else:
+ x = C()
+ t = type(x)
+ return issubclass(t, A)
+
+ def f():
+ x = g(1)
+ y = g(0)
+ return x or y
+ a = self.RPythonAnnotator()
+ s = a.build_types(f, [])
+ assert s.knowntype == bool
+ assert not s.is_constant()
+ a = self.RPythonAnnotator()
+ # sanity check
+ x = annmodel.SomeInteger()
+ x.const = 1
+ s = a.build_types(g, [x])
+ assert s.const == False
+ a = self.RPythonAnnotator()
+ x = annmodel.SomeInteger()
+ x.const = 2
+ s = a.build_types(g, [x])
+ assert s.const == True
def g(n):
return [0,1,2,n]
More information about the Pypy-commit
mailing list