[pypy-svn] r18375 - in pypy/dist/pypy/rpython/ootype: . test
boria at codespeak.net
boria at codespeak.net
Tue Oct 11 11:06:16 CEST 2005
Author: boria
Date: Tue Oct 11 11:06:16 2005
New Revision: 18375
Modified:
pypy/dist/pypy/rpython/ootype/ootype.py
pypy/dist/pypy/rpython/ootype/test/test_ootype.py
Log:
* Null values: checkpoint.
Modified: pypy/dist/pypy/rpython/ootype/ootype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootype/ootype.py (original)
+++ pypy/dist/pypy/rpython/ootype/ootype.py Tue Oct 11 11:06:16 2005
@@ -169,9 +169,30 @@
self.__dict__[name] = value
+class _null_instance(_instance):
+
+ def __init__(self, CLASS):
+ _instance.__init__(self, CLASS)
+
+ def __getattribute__(self, name):
+ if name.startswith("_"):
+ return object.__getattribute__(self, name)
+
+ _instance.__getattr__(self, name)
+
+ raise RuntimeError("Access to field in null object")
+
+ def __setattr__(self, name, value):
+ _instance.__setattr__(self, name, value)
+
+ raise RuntimeError("Assignment to field in null object")
+
def new(CLASS):
return _instance(CLASS)
+def null(CLASS):
+ return _null_instance(CLASS)
+
def typeOf(val):
try:
return val._TYPE
Modified: pypy/dist/pypy/rpython/ootype/test/test_ootype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootype/test/test_ootype.py (original)
+++ pypy/dist/pypy/rpython/ootype/test/test_ootype.py Tue Oct 11 11:06:16 2005
@@ -23,3 +23,11 @@
assert c.a == 3
py.test.raises(TypeError, "Class('test', None, {'a': (Signed, 3.0)})")
+
+def test_simple_null():
+ C = Class("test", None, {"a": Signed})
+
+ c = null(C)
+ assert typeOf(c) == C
+
+ py.test.raises(RuntimeError, "c.a")
More information about the Pypy-commit
mailing list