[pypy-svn] r66979 - in pypy/branch/pyjitpl5/pypy: annotation annotation/test rpython rpython/test
arigo at codespeak.net
arigo at codespeak.net
Wed Aug 19 16:09:56 CEST 2009
Author: arigo
Date: Wed Aug 19 16:09:56 2009
New Revision: 66979
Modified:
pypy/branch/pyjitpl5/pypy/annotation/test/test_annrpython.py
pypy/branch/pyjitpl5/pypy/annotation/unaryop.py
pypy/branch/pyjitpl5/pypy/rpython/rpbc.py
pypy/branch/pyjitpl5/pypy/rpython/test/test_rclass.py
Log:
Support hash(None) as part of hash(instance-or-None).
Modified: pypy/branch/pyjitpl5/pypy/annotation/test/test_annrpython.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/annotation/test/test_annrpython.py (original)
+++ pypy/branch/pyjitpl5/pypy/annotation/test/test_annrpython.py Wed Aug 19 16:09:56 2009
@@ -3106,6 +3106,15 @@
s = a.build_types(f, [int])
assert s.const == 0
+ def test_hash(self):
+ class A(object):
+ pass
+ def f():
+ return hash(A()) + hash(None)
+ a = self.RPythonAnnotator()
+ s = a.build_types(f, [])
+ assert s.knowntype == int
+
def g(n):
return [0,1,2,n]
Modified: pypy/branch/pyjitpl5/pypy/annotation/unaryop.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/annotation/unaryop.py (original)
+++ pypy/branch/pyjitpl5/pypy/annotation/unaryop.py Wed Aug 19 16:09:56 2009
@@ -683,6 +683,13 @@
else:
return SomeObject() # len() on a pbc? no chance
+ def hash(pbc):
+ if pbc.isNone():
+ # only supports hash(None) as part of hash(<SomeInstance>)
+ return SomeInteger()
+ else:
+ return SomeObject.hash(pbc)
+
class __extend__(SomeGenericCallable):
def call(self, args):
bookkeeper = getbookkeeper()
Modified: pypy/branch/pyjitpl5/pypy/rpython/rpbc.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/rpython/rpbc.py (original)
+++ pypy/branch/pyjitpl5/pypy/rpython/rpbc.py Wed Aug 19 16:09:56 2009
@@ -609,11 +609,17 @@
def ll_str(self, none):
return llstr("None")
+ def get_ll_hash_function(self):
+ return ll_none_hash
+
rtype_simple_call = none_call
rtype_call_args = none_call
none_frozen_pbc_repr = NoneFrozenPBCRepr()
+def ll_none_hash(_):
+ return 0
+
class __extend__(pairtype(Repr, NoneFrozenPBCRepr)):
Modified: pypy/branch/pyjitpl5/pypy/rpython/test/test_rclass.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/rpython/test/test_rclass.py (original)
+++ pypy/branch/pyjitpl5/pypy/rpython/test/test_rclass.py Wed Aug 19 16:09:56 2009
@@ -673,6 +673,13 @@
res = self.interpret(fn, [0])
assert res == 0
+ def test_hash_of_only_none(self):
+ def fn():
+ obj = None
+ return hash(obj)
+ res = self.interpret(fn, [])
+ assert res == 0
+
class TestLltype(BaseTestRclass, LLRtypeMixin):
More information about the Pypy-commit
mailing list