[pypy-svn] r68272 - in pypy/trunk/pypy/rlib: . test
antocuni at codespeak.net
antocuni at codespeak.net
Fri Oct 9 14:58:13 CEST 2009
Author: antocuni
Date: Fri Oct 9 14:58:12 2009
New Revision: 68272
Modified:
pypy/trunk/pypy/rlib/nonconst.py
pypy/trunk/pypy/rlib/test/test_nonconst.py
Log:
make sure we can use the idiom "if NonConstant(False): ..." to make the
annotator seeing some code without executing it
Modified: pypy/trunk/pypy/rlib/nonconst.py
==============================================================================
--- pypy/trunk/pypy/rlib/nonconst.py (original)
+++ pypy/trunk/pypy/rlib/nonconst.py Fri Oct 9 14:58:12 2009
@@ -17,6 +17,9 @@
def __setattr__(self, attr, value):
setattr(self.__dict__['constant'], attr, value)
+ def __nonzero__(self):
+ return bool(self.__dict__['constant'])
+
class EntryNonConstant(ExtRegistryEntry):
_about_ = NonConstant
Modified: pypy/trunk/pypy/rlib/test/test_nonconst.py
==============================================================================
--- pypy/trunk/pypy/rlib/test/test_nonconst.py (original)
+++ pypy/trunk/pypy/rlib/test/test_nonconst.py Fri Oct 9 14:58:12 2009
@@ -47,3 +47,15 @@
if option.view:
a.translator.view()
assert isinstance(s, SomeInstance)
+
+def test_bool_nonconst():
+ def fn():
+ return bool(NonConstant(False))
+
+ assert not fn()
+
+ a = RPythonAnnotator()
+ s = a.build_types(fn, [])
+ assert s.knowntype is bool
+ assert not hasattr(s, 'const')
+
More information about the Pypy-commit
mailing list