[pypy-svn] r8561 - in pypy/dist/pypy: annotation translator/test
adim at codespeak.net
adim at codespeak.net
Tue Jan 25 15:00:27 CET 2005
Author: adim
Date: Tue Jan 25 15:00:27 2005
New Revision: 8561
Modified:
pypy/dist/pypy/annotation/unaryop.py
pypy/dist/pypy/translator/test/snippet.py
pypy/dist/pypy/translator/test/test_annrpython.py
Log:
SomeDict.update + tests
also, converted a few tabs inadvertantly introduced in the
earlier checkins.
Modified: pypy/dist/pypy/annotation/unaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/unaryop.py (original)
+++ pypy/dist/pypy/annotation/unaryop.py Tue Jan 25 15:00:27 2005
@@ -11,7 +11,7 @@
from pypy.annotation.model import SomeInstance, SomeBuiltin
from pypy.annotation.model import SomeIterator, SomePBC, new_or_old_class
from pypy.annotation.model import unionof, set, setunion, missing_operation
-from pypy.annotation.factory import BlockedInference
+from pypy.annotation.factory import BlockedInference, generalize
from pypy.annotation.bookkeeper import getbookkeeper
from pypy.annotation.classdef import isclassdef
@@ -110,10 +110,13 @@
class __extend__(SomeDict):
def iter(dct):
- return SomeIterator(dct.s_key)
+ return SomeIterator(dct.s_key)
def method_copy(dct):
- return SomeDict(dct.factories, dct.s_key, dct.s_value)
+ return SomeDict(dct.factories, dct.s_key, dct.s_value)
+
+ def method_update(dct1, dct2):
+ generalize(dct1.factories, dct2.s_key, dct2.s_value)
class __extend__(SomeString):
Modified: pypy/dist/pypy/translator/test/snippet.py
==============================================================================
--- pypy/dist/pypy/translator/test/snippet.py (original)
+++ pypy/dist/pypy/translator/test/snippet.py Tue Jan 25 15:00:27 2005
@@ -664,3 +664,8 @@
def dict_copy(d):
return d.copy()
+
+def dict_update(x):
+ d = {x:x}
+ d.update({1:2})
+ return d
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 Tue Jan 25 15:00:27 2005
@@ -402,20 +402,33 @@
a = RPythonAnnotator()
s = a.build_types(snippet.simple_iter, [list])
assert isinstance(s, annmodel.SomeIterator)
-
+
def test_simple_iter_dict(self):
a = RPythonAnnotator()
- t = annmodel.SomeDict({}, annmodel.SomeInteger(), annmodel.SomeInteger())
+ t = annmodel.SomeDict({}, annmodel.SomeInteger(), annmodel.SomeInteger())
s = a.build_types(snippet.simple_iter, [t])
assert isinstance(s, annmodel.SomeIterator)
-
+
def test_dict_copy(self):
a = RPythonAnnotator()
- t = annmodel.SomeDict({}, annmodel.SomeInteger(), annmodel.SomeInteger())
+ t = annmodel.SomeDict({}, annmodel.SomeInteger(), annmodel.SomeInteger())
s = a.build_types(snippet.dict_copy, [t])
- assert isinstance(s, annmodel.SomeDict)
- assert isinstance(s.s_key, annmodel.SomeInteger)
- assert isinstance(s.s_value, annmodel.SomeInteger)
+ assert isinstance(s, annmodel.SomeDict)
+ assert isinstance(s.s_key, annmodel.SomeInteger)
+ assert isinstance(s.s_value, annmodel.SomeInteger)
+
+ def test_dict_update(self):
+ a = RPythonAnnotator()
+ s = a.build_types(snippet.dict_update, [int])
+ assert isinstance(s, annmodel.SomeDict)
+ assert isinstance(s.s_key, annmodel.SomeInteger)
+ assert isinstance(s.s_value, annmodel.SomeInteger)
+
+ a = RPythonAnnotator()
+ s = a.build_types(snippet.dict_update, [str])
+ assert isinstance(s, annmodel.SomeDict)
+ assert not isinstance(s.s_key, annmodel.SomeString)
+ assert not isinstance(s.s_value, annmodel.SomeString)
def g(n):
More information about the Pypy-commit
mailing list