[pypy-svn] r26477 - in pypy/dist/pypy/rpython/ootypesystem: . test
nik at codespeak.net
nik at codespeak.net
Fri Apr 28 04:04:11 CEST 2006
Author: nik
Date: Fri Apr 28 04:04:08 2006
New Revision: 26477
Modified:
pypy/dist/pypy/rpython/ootypesystem/ootype.py
pypy/dist/pypy/rpython/ootypesystem/test/test_oodict.py
Log:
i discovered we don't only want lazily initialized value types for Dicts, but
also key types.
Modified: pypy/dist/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/ootype.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/ootype.py Fri Apr 28 04:04:08 2006
@@ -352,14 +352,17 @@
KEYTYPE_T = object()
VALUETYPE_T = object()
- def __init__(self, KEYTYPE, VALUETYPE=None):
+ def __init__(self, KEYTYPE=None, VALUETYPE=None):
self._KEYTYPE = KEYTYPE
self._VALUETYPE = VALUETYPE
self._null = _null_dict(self)
- if VALUETYPE is not None:
+ if self._is_initialized():
self._init_methods()
+ def _is_initialized(self):
+ return self._KEYTYPE is not None and self._VALUETYPE is not None
+
def _init_methods(self):
generic_types = {
self.SELFTYPE_T: self,
@@ -393,12 +396,12 @@
def __eq__(self, other):
if not isinstance(other, Dict):
return False
- if self._VALUETYPE is None or other._VALUETYPE is None:
+ if not self._is_initialized() or not other._is_initialized():
raise TypeError("Can't compare uninitialized Dict type.")
return BuiltinADTType.__eq__(self, other)
def __hash__(self):
- if self._VALUETYPE is None:
+ if not self._is_initialized():
raise TypeError("Can't hash uninitialized Dict type.")
return BuiltinADTType.__hash__(self)
@@ -410,7 +413,8 @@
VALUETYPE = self._specialize_type(self._VALUETYPE, generic_types)
return self.__class__(KEYTYPE, VALUETYPE)
- def _set_valuetype(self, VALUETYPE):
+ def _set_types(self, KEYTYPE, VALUETYPE):
+ self._KEYTYPE = KEYTYPE
self._VALUETYPE = VALUETYPE
self._init_methods()
@@ -986,11 +990,11 @@
def hasItemType(LIST):
return LIST._ITEMTYPE is not None
-def setValueType(DICT, VALUETYPE):
- return DICT._set_valuetype(VALUETYPE)
+def setDictTypes(DICT, KEYTYPE, VALUETYPE):
+ return DICT._set_types(KEYTYPE, VALUETYPE)
-def hasValueType(DICT):
- return DICT._VALUETYPE is not None
+def hasDictTypes(DICT):
+ return DICT._is_initialized()
ROOT = Instance('Root', None, _is_root=True)
Modified: pypy/dist/pypy/rpython/ootypesystem/test/test_oodict.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/test/test_oodict.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/test/test_oodict.py Fri Apr 28 04:04:08 2006
@@ -1,6 +1,6 @@
import py
from pypy.rpython.test.test_llinterp import interpret
-from pypy.rpython.ootypesystem.ootype import Signed, Float, Dict, new, typeOf, setValueType
+from pypy.rpython.ootypesystem.ootype import Signed, Float, Dict, new, typeOf, setDictTypes
def test_new():
DT = Dict(Signed, Float)
@@ -31,21 +31,21 @@
items.sort()
assert items == [(42, 43.0), (52, 53.0)]
-def test_optional_valuetype():
- DT = Dict(Signed)
+def test_optional_types():
+ DT = Dict()
DT2 = Dict(Signed, Float)
assert DT != Signed
py.test.raises(TypeError, "DT == DT2")
py.test.raises(TypeError, "DT2 == DT")
py.test.raises(TypeError, hash, DT)
- setValueType(DT, Float)
+ setDictTypes(DT, Signed, Float)
assert DT == DT2
assert DT2 == DT
assert hash(DT) == hash(DT2)
def test_recursive_str_hash():
- DT = Dict(Signed)
- setValueType(DT, DT)
+ DT = Dict()
+ setDictTypes(DT, Signed, DT)
assert isinstance(str(DT), str)
assert isinstance(hash(DT), int)
More information about the Pypy-commit
mailing list