[pypy-svn] rev 2450 - in pypy/trunk/src/pypy/annotation: . test
arigo at codespeak.net
arigo at codespeak.net
Wed Dec 17 16:21:58 CET 2003
Author: arigo
Date: Wed Dec 17 16:21:57 2003
New Revision: 2450
Modified:
pypy/trunk/src/pypy/annotation/annset.py
pypy/trunk/src/pypy/annotation/model.py
pypy/trunk/src/pypy/annotation/test/test_annset.py
Log:
The tests pass again.
Modified: pypy/trunk/src/pypy/annotation/annset.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/annset.py (original)
+++ pypy/trunk/src/pypy/annotation/annset.py Wed Dec 17 16:21:57 2003
@@ -1,8 +1,11 @@
from __future__ import generators
import types
-from model import Annotation, SomeValue, ANN
+from model import Annotation, SomeValue, QueryArgument, ANN
from model import immutable_types, blackholevalue, basicannotations
+QUERYARG = QueryArgument()
+
+
class AnnotationSet:
"""An annotation set is a (large) family of Annotations."""
@@ -61,15 +64,15 @@
the queried value. """
# slightly limited implementation for ease of coding :-)
- assert query.args.count(Ellipsis) == 1, (
+ assert query.args.count(QUERYARG) == 1, (
"sorry, the algorithm is a bit too naive for this case")
- queryarg = query.args.index(Ellipsis)
+ queryarg = query.args.index(QUERYARG)
for ann in self._annmatches(query):
# does the returned match also agree with the other queries?
match = ann.args[queryarg]
depends = [ann]
for queryann in querylist:
- boundquery = queryann.copy(renameargs={Ellipsis: match})
+ boundquery = queryann.copy(renameargs={QUERYARG: match})
ann = self.findfirst(boundquery)
if ann is None:
break
@@ -80,7 +83,7 @@
def _annmatches(self, queryann):
""" yield annotations matching the given queryannotation. """
testindices = [i for i in range(queryann.predicate.arity)
- if queryann.args[i] is not Ellipsis]
+ if queryann.args[i] is not QUERYARG]
for ann in self.annlist:
if ann.predicate == queryann.predicate:
for i in testindices:
@@ -184,8 +187,8 @@
deps.append(ann)
def check_type(self, someval, checktype):
- return self.query(ANN.type[someval, ...],
- ANN.constant(checktype)[...])
+ return bool(self.query(ANN.type[someval, QUERYARG],
+ ANN.constant(checktype)[QUERYARG]))
def set_type(self, someval, knowntype):
typeval = SomeValue()
Modified: pypy/trunk/src/pypy/annotation/model.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/model.py (original)
+++ pypy/trunk/src/pypy/annotation/model.py Wed Dec 17 16:21:57 2003
@@ -3,6 +3,9 @@
class SomeValue:
pass
+class QueryArgument:
+ pass
+
class Predicate:
def __init__(self, debugname, arity):
self.debugname = debugname
@@ -42,7 +45,8 @@
# note that for predicates that are simple operations like
# op.add, the result is stored as the last argument.
for someval in args:
- assert someval is Ellipsis or isinstance(someval, SomeValue) # bug catcher
+ assert isinstance(someval, (SomeValue, QueryArgument,
+ type(Ellipsis))) # bug catcher
def copy(self, renameargs={}):
args = [renameargs.get(arg, arg) for arg in self.args]
@@ -76,7 +80,7 @@
}
# a conventional value for representing 'all Annotations match this one'
-blackholevalue = SomeValue()
+blackholevalue = Ellipsis
# a few values representing 'any value of the given type'
# the following loops creates intvalue, strvalue, etc.
Modified: pypy/trunk/src/pypy/annotation/test/test_annset.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/test/test_annset.py (original)
+++ pypy/trunk/src/pypy/annotation/test/test_annset.py Wed Dec 17 16:21:57 2003
@@ -3,7 +3,7 @@
from pypy.tool import test
from pypy.annotation.model import ANN, SomeValue
-from pypy.annotation.annset import AnnotationSet
+from pypy.annotation.annset import AnnotationSet, QUERYARG
class TestAnnotationSet(test.IntTestCase):
@@ -43,15 +43,15 @@
c1,c2,c3 = SomeValue(), SomeValue(), SomeValue()
lst = [ANN.add[c1, c3, c2]]
a = AnnotationSet(lst)
- c = a.query(ANN.add[c1, c3, ...])
- self.assertEquals(c, [c2])
- c = a.query(ANN.add[c1, ..., c2])
- self.assertEquals(c, [c3])
- c = a.query(ANN.add[..., c3, c2])
- self.assertEquals(c, [c1])
+ clist = a.query(ANN.add[c1, c3, QUERYARG])
+ self.assertEquals(clist, [c2])
+ clist = a.query(ANN.add[c1, QUERYARG, c2])
+ self.assertEquals(clist, [c3])
+ clist = a.query(ANN.add[QUERYARG, c3, c2])
+ self.assertEquals(clist, [c1])
- c = a.query(ANN.add[..., c1, c2])
- self.assertEquals(c, [])
+ clist = a.query(ANN.add[QUERYARG, c1, c2])
+ self.assertEquals(clist, [])
def test_query_multiple_annotations(self):
c1,c2,c3 = SomeValue(), SomeValue(), SomeValue()
@@ -60,9 +60,9 @@
ANN.type[c2, c3],
]
a = AnnotationSet(lst)
- c = a.query(ANN.add[c1, c3, ...],
- ANN.type[..., c3])
- self.assertEquals(c, [c2])
+ clist = a.query(ANN.add[c1, c3, QUERYARG],
+ ANN.type[QUERYARG, c3])
+ self.assertEquals(clist, [c2])
def test_constant(self):
c1,c2,c3 = SomeValue(), SomeValue(), SomeValue()
@@ -70,8 +70,8 @@
ANN.constant(42)[c1],
]
a = AnnotationSet(lst)
- c = a.query(ANN.constant(42)[...])
- self.assertEquals(c, [c1])
+ clist = a.query(ANN.constant(42)[QUERYARG])
+ self.assertEquals(clist, [c1])
c1,c2,c3,c4 = SomeValue(), SomeValue(), SomeValue(), SomeValue()
@@ -102,7 +102,7 @@
def test_simple(self):
a = self.annset
def f(rec):
- if rec.query(ANN.add[c1, c3, ...]):
+ if rec.query(ANN.add[c1, c3, QUERYARG]):
rec.set(ANN.type[c1, c3])
a.record(f)
self.assertSameSet(a, a, self.lst + [ANN.type[c1, c3]])
@@ -116,8 +116,8 @@
if rec.check_type(c1, int):
rec.set_type(c2, str)
a.record(f)
- self.assert_(a.query(ANN.type[c2, ...],
- ANN.constant(str)[...]))
+ self.assert_(a.query(ANN.type[c2, QUERYARG],
+ ANN.constant(str)[QUERYARG]))
if __name__ == '__main__':
test.main()
More information about the Pypy-commit
mailing list