[pypy-svn] r18498 - in pypy/branch/hl-backend/pypy: annotation annotation/test rpython/ootype rpython/ootype/test
ac at codespeak.net
ac at codespeak.net
Wed Oct 12 18:34:39 CEST 2005
Author: ac
Date: Wed Oct 12 18:34:39 2005
New Revision: 18498
Modified:
pypy/branch/hl-backend/pypy/annotation/binaryop.py
pypy/branch/hl-backend/pypy/annotation/bookkeeper.py
pypy/branch/hl-backend/pypy/annotation/builtin.py
pypy/branch/hl-backend/pypy/annotation/model.py
pypy/branch/hl-backend/pypy/annotation/test/test_model.py
pypy/branch/hl-backend/pypy/annotation/unaryop.py
pypy/branch/hl-backend/pypy/rpython/ootype/ootype.py
pypy/branch/hl-backend/pypy/rpython/ootype/test/test_ooann.py
pypy/branch/hl-backend/pypy/rpython/ootype/test/test_ootype.py
Log:
Restructure the typemodel of ootype.
Modified: pypy/branch/hl-backend/pypy/annotation/binaryop.py
==============================================================================
--- pypy/branch/hl-backend/pypy/annotation/binaryop.py (original)
+++ pypy/branch/hl-backend/pypy/annotation/binaryop.py Wed Oct 12 18:34:39 2005
@@ -652,7 +652,8 @@
# ____________________________________________________________
# annotation of low-level types
-from pypy.annotation.model import SomePtr, SomeRef, ll_to_annotation, annotation_to_lltype
+from pypy.annotation.model import SomePtr, SomeOOInstance, SomeOOClass
+from pypy.annotation.model import ll_to_annotation, annotation_to_lltype
from pypy.rpython.ootype import ootype
class __extend__(pairtype(SomePtr, SomePtr)):
@@ -688,17 +689,23 @@
return pair(p2, obj).union()
-class __extend__(pairtype(SomeRef, SomeRef)):
+class __extend__(pairtype(SomeOOInstance, SomeOOInstance)):
+ def union((r1, r2)):
+ common = ootype.commonBaseclass(r1.ootype, r2.ootype)
+ assert common is not None, 'Mixing of incompatible instances %r, %r' %(r1.ootype, r2.ootype)
+ return SomeOOInstance(common)
+
+class __extend__(pairtype(SomeOOClass, SomeOOClass)):
def union((r1, r2)):
common = ootype.commonBaseclass(r1.ootype, r2.ootype)
assert common is not None, 'Mixing of incompatible classes %r, %r' %(r1.ootype, r2.ootype)
- return SomeRef(common)
+ return SomeOOClass(common)
-class __extend__(pairtype(SomeRef, SomeObject)):
+class __extend__(pairtype(SomeOOInstance, SomeObject)):
def union((r, obj)):
assert False, ("mixing reference type %r with something else %r" % (r.ootype, obj))
-class __extend__(pairtype(SomeObject, SomeRef)):
+class __extend__(pairtype(SomeObject, SomeOOInstance)):
def union((obj, r2)):
return pair(r2, obj).union()
Modified: pypy/branch/hl-backend/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/branch/hl-backend/pypy/annotation/bookkeeper.py (original)
+++ pypy/branch/hl-backend/pypy/annotation/bookkeeper.py Wed Oct 12 18:34:39 2005
@@ -354,7 +354,7 @@
assert x is lladdress.NULL
result= SomeAddress(is_null=True)
elif isinstance(x, ootype._static_meth):
- result = SomeStaticMeth(ootype.typeOf(x))
+ result = SomeOOStaticMeth(ootype.typeOf(x))
elif callable(x) or isinstance(x, staticmethod): # XXX
# maybe 'x' is a method bound to a not-yet-frozen cache?
# fun fun fun.
Modified: pypy/branch/hl-backend/pypy/annotation/builtin.py
==============================================================================
--- pypy/branch/hl-backend/pypy/annotation/builtin.py (original)
+++ pypy/branch/hl-backend/pypy/annotation/builtin.py Wed Oct 12 18:34:39 2005
@@ -365,29 +365,39 @@
BUILTIN_ANALYZERS[lltype.runtime_type_info] = runtime_type_info
# ootype
-from pypy.annotation.model import SomeRef
+from pypy.annotation.model import SomeOOInstance, SomeOOClass
from pypy.rpython.ootype import ootype
-def new(C):
- assert C.is_constant()
- i = ootype.new(C.const)
- r = SomeRef(ootype.typeOf(i))
+def new(I):
+ assert I.is_constant()
+ i = ootype.new(I.const)
+ r = SomeOOInstance(ootype.typeOf(i))
return r
-def null(C):
- assert C.is_constant()
- i = ootype.null(C.const)
- r = SomeRef(ootype.typeOf(i))
+def null(I):
+ assert I.is_constant()
+ i = ootype.null(I.const)
+ r = SomeOOInstance(ootype.typeOf(i))
return r
-def instanceof(c, C):
- assert C.is_constant()
- assert isinstance(C.const, ootype.Class)
+def instanceof(i, I):
+ assert I.is_constant()
+ assert isinstance(I.const, ootype.Instance)
return SomeBool()
+def classof(i):
+ assert isinstance(i, SomeOOInstance)
+ return SomeOOClass(i.ootype)
+
+def runtimenew(c):
+ assert isinstance(c, SomeOOClass)
+ return SomeOOInstance(c.ootype)
+
BUILTIN_ANALYZERS[ootype.instanceof] = instanceof
BUILTIN_ANALYZERS[ootype.new] = new
BUILTIN_ANALYZERS[ootype.null] = null
+BUILTIN_ANALYZERS[ootype.runtimenew] = runtimenew
+BUILTIN_ANALYZERS[ootype.classof] = classof
#________________________________
# non-gc objects
Modified: pypy/branch/hl-backend/pypy/annotation/model.py
==============================================================================
--- pypy/branch/hl-backend/pypy/annotation/model.py (original)
+++ pypy/branch/hl-backend/pypy/annotation/model.py Wed Oct 12 18:34:39 2005
@@ -431,16 +431,20 @@
def can_be_none(self):
return False
-class SomeRef(SomeObject):
+class SomeOOClass(SomeObject):
def __init__(self, ootype):
self.ootype = ootype
-class SomeBoundMeth(SomeObject):
+class SomeOOInstance(SomeObject):
+ def __init__(self, ootype):
+ self.ootype = ootype
+
+class SomeOOBoundMeth(SomeObject):
def __init__(self, ootype, name):
self.ootype = ootype
self.name = name
-class SomeStaticMeth(SomeObject):
+class SomeOOStaticMeth(SomeObject):
def __init__(self, method):
self.method = method
@@ -459,7 +463,7 @@
]
def annotation_to_lltype(s_val, info=None):
- if isinstance(s_val, SomeRef):
+ if isinstance(s_val, SomeOOInstance):
return s_val.ootype
if isinstance(s_val, SomePtr):
return s_val.ll_ptrtype
@@ -478,8 +482,8 @@
def lltype_to_annotation(T):
s = ll_to_annotation_map.get(T)
if s is None:
- if isinstance(T, ootype.Class):
- return SomeRef(T)
+ if isinstance(T, ootype.Instance):
+ return SomeOOInstance(T)
else:
return SomePtr(T)
else:
Modified: pypy/branch/hl-backend/pypy/annotation/test/test_model.py
==============================================================================
--- pypy/branch/hl-backend/pypy/annotation/test/test_model.py (original)
+++ pypy/branch/hl-backend/pypy/annotation/test/test_model.py Wed Oct 12 18:34:39 2005
@@ -118,9 +118,9 @@
assert isinstance(s_p, SomePtr) and s_p.ll_ptrtype == lltype.Ptr(S)
s_p = ll_to_annotation(lltype.malloc(A, 0))
assert isinstance(s_p, SomePtr) and s_p.ll_ptrtype == lltype.Ptr(A)
- C = ootype.Class('C', None, {})
+ C = ootype.Instance('C', None, {})
s_p = ll_to_annotation(ootype.new(C))
- assert isinstance(s_p, SomeRef) and s_p.ootype == C
+ assert isinstance(s_p, SomeOOInstance) and s_p.ootype == C
def test_annotation_to_lltype():
from pypy.rpython.rarithmetic import r_uint
@@ -143,8 +143,8 @@
s_p = SomePtr(ll_ptrtype=PS)
assert annotation_to_lltype(s_p) == PS
py.test.raises(ValueError, "annotation_to_lltype(si0)")
- C = ootype.Class('C', None, {})
- ref = SomeRef(C)
+ C = ootype.Instance('C', None, {})
+ ref = SomeOOInstance(C)
assert annotation_to_lltype(ref) == C
def test_ll_union():
@@ -173,24 +173,24 @@
py.test.raises(AssertionError, "unionof(SomeObject(), SomePtr(PS1))")
def test_oo_union():
- C1 = ootype.Class("C1", None)
- C2 = ootype.Class("C2", C1)
- C3 = ootype.Class("C3", C1)
- D = ootype.Class("D", None)
- assert unionof(SomeRef(C1), SomeRef(C1)) == SomeRef(C1)
- assert unionof(SomeRef(C1), SomeRef(C2)) == SomeRef(C1)
- assert unionof(SomeRef(C2), SomeRef(C1)) == SomeRef(C1)
- assert unionof(SomeRef(C2), SomeRef(C3)) == SomeRef(C1)
-
- assert unionof(SomeRef(C1),SomeImpossibleValue()) == SomeRef(C1)
- assert unionof(SomeImpossibleValue(), SomeRef(C1)) == SomeRef(C1)
-
- py.test.raises(AssertionError, "unionof(SomeRef(C1), SomeRef(D))")
- py.test.raises(AssertionError, "unionof(SomeRef(D), SomeRef(C1))")
- py.test.raises(AssertionError, "unionof(SomeRef(C1), SomeInteger())")
- py.test.raises(AssertionError, "unionof(SomeInteger(), SomeRef(C1))")
- py.test.raises(AssertionError, "unionof(SomeRef(C1), SomeObject())")
- py.test.raises(AssertionError, "unionof(SomeObject(), SomeRef(C1))")
+ C1 = ootype.Instance("C1", None)
+ C2 = ootype.Instance("C2", C1)
+ C3 = ootype.Instance("C3", C1)
+ D = ootype.Instance("D", None)
+ assert unionof(SomeOOInstance(C1), SomeOOInstance(C1)) == SomeOOInstance(C1)
+ assert unionof(SomeOOInstance(C1), SomeOOInstance(C2)) == SomeOOInstance(C1)
+ assert unionof(SomeOOInstance(C2), SomeOOInstance(C1)) == SomeOOInstance(C1)
+ assert unionof(SomeOOInstance(C2), SomeOOInstance(C3)) == SomeOOInstance(C1)
+
+ assert unionof(SomeOOInstance(C1),SomeImpossibleValue()) == SomeOOInstance(C1)
+ assert unionof(SomeImpossibleValue(), SomeOOInstance(C1)) == SomeOOInstance(C1)
+
+ py.test.raises(AssertionError, "unionof(SomeOOInstance(C1), SomeOOInstance(D))")
+ py.test.raises(AssertionError, "unionof(SomeOOInstance(D), SomeOOInstance(C1))")
+ py.test.raises(AssertionError, "unionof(SomeOOInstance(C1), SomeInteger())")
+ py.test.raises(AssertionError, "unionof(SomeInteger(), SomeOOInstance(C1))")
+ py.test.raises(AssertionError, "unionof(SomeOOInstance(C1), SomeObject())")
+ py.test.raises(AssertionError, "unionof(SomeObject(), SomeOOInstance(C1))")
if __name__ == '__main__':
for name, value in globals().items():
Modified: pypy/branch/hl-backend/pypy/annotation/unaryop.py
==============================================================================
--- pypy/branch/hl-backend/pypy/annotation/unaryop.py (original)
+++ pypy/branch/hl-backend/pypy/annotation/unaryop.py Wed Oct 12 18:34:39 2005
@@ -566,7 +566,7 @@
# annotation of low-level types
-from pypy.annotation.model import SomePtr, SomeRef, SomeBoundMeth, SomeStaticMeth
+from pypy.annotation.model import SomePtr, SomeOOInstance, SomeOOBoundMeth, SomeOOStaticMeth
from pypy.annotation.model import ll_to_annotation, annotation_to_lltype
class __extend__(SomePtr):
@@ -595,22 +595,22 @@
return SomeBool()
from pypy.rpython.ootype import ootype
-class __extend__(SomeRef):
+class __extend__(SomeOOInstance):
def getattr(r, s_attr):
assert s_attr.is_constant(), "getattr on ref %r with non-constant field-name" % r.ootype
v = getattr(r.ootype._example(), s_attr.const)
if isinstance(v, ootype._bound_meth):
- return SomeBoundMeth(r.ootype, s_attr.const)
+ return SomeOOBoundMeth(r.ootype, s_attr.const)
return ll_to_annotation(v)
-class __extend__(SomeBoundMeth):
+class __extend__(SomeOOBoundMeth):
def simple_call(m, *args_s):
llargs = [annotation_to_lltype(arg_s)._example() for arg_s in args_s]
inst = m.ootype._example()
v = getattr(inst, m.name)(*llargs)
return ll_to_annotation(v)
-class __extend__(SomeStaticMeth):
+class __extend__(SomeOOStaticMeth):
def simple_call(m, *args_s):
llargs = [annotation_to_lltype(arg_s)._example() for arg_s in args_s]
smeth = m.method._example()
Modified: pypy/branch/hl-backend/pypy/rpython/ootype/ootype.py
==============================================================================
--- pypy/branch/hl-backend/pypy/rpython/ootype/ootype.py (original)
+++ pypy/branch/hl-backend/pypy/rpython/ootype/ootype.py Wed Oct 12 18:34:39 2005
@@ -12,7 +12,11 @@
pass
class Class(OOType):
+ pass
+Class = Class()
+class Instance(OOType):
+ """this is the type of user-defined objects"""
def __init__(self, name, superclass, fields={}, methods={}):
self._name = name
self._superclass = superclass
@@ -24,7 +28,8 @@
self._add_methods(methods)
self._null = _null_instance(self)
-
+ self._class = _class(self)
+
def _defl(self):
return self._null
@@ -110,13 +115,17 @@
StaticMethod.__init__(self, args, result)
# ____________________________________________________________
+class _class(object):
+ _TYPE = Class
+ def __init__(self, INSTANCE):
+ self._INSTANCE = INSTANCE
+
class _instance(object):
- def __init__(self, CLASS):
- self.__dict__["_TYPE"] = CLASS
-
- CLASS._init_instance(self)
-
+ def __init__(self, INSTANCE):
+ self.__dict__["_TYPE"] = INSTANCE
+ INSTANCE._init_instance(self)
+
def __getattr__(self, name):
meth = self._TYPE._lookup(name)
if meth is not None:
@@ -136,8 +145,8 @@
class _null_instance(_instance):
- def __init__(self, CLASS):
- self.__dict__["_TYPE"] = CLASS
+ def __init__(self, INSTANCE):
+ self.__dict__["_TYPE"] = INSTANCE
def __getattribute__(self, name):
if name.startswith("_"):
@@ -166,7 +175,7 @@
for a, ARG in zip(args, self._TYPE.ARGS):
if typeOf(a) != ARG:
- if isinstance(ARG, Class) and isinstance(a, _instance):
+ if isinstance(ARG, Instance) and isinstance(a, _instance):
if instanceof(a, ARG):
continue
raise TypeError,"calling %r with wrong argument types: %r" % (self._TYPE, args)
@@ -205,8 +214,12 @@
def __call__(self, *args):
return self.meth._checkargs(args)(self.inst, *args)
-def new(CLASS):
- return _instance(CLASS)
+def new(INSTANCE):
+ return _instance(INSTANCE)
+
+def runtimenew(class_):
+ assert isinstance(class_, _class)
+ return _instance(class_._INSTANCE)
def static_meth(FUNCTION, name, **attrs):
return _static_meth(FUNCTION, _name=name, **attrs)
@@ -214,17 +227,24 @@
def meth(METHOD, **attrs):
return _meth(METHOD, **attrs)
-def null(CLASS):
- return CLASS._null
+def null(INSTANCE):
+ return INSTANCE._null
+
+def instanceof(inst, INSTANCE):
+ return isSubclass(inst._TYPE, INSTANCE)
+
+def classof(inst):
+ return runtimeClass(inst._TYPE)
-def addFields(CLASS, fields):
- CLASS._add_fields(fields)
+def addFields(INSTANCE, fields):
+ INSTANCE._add_fields(fields)
-def addMethods(CLASS, methods):
- CLASS._add_methods(methods)
+def addMethods(INSTANCE, methods):
+ INSTANCE._add_methods(methods)
-def instanceof(inst, CLASS):
- return isSubclass(inst._TYPE, CLASS)
+def runtimeClass(INSTANCE):
+ assert isinstance(INSTANCE, Instance)
+ return INSTANCE._class
def isSubclass(C1, C2):
c = C1
@@ -234,10 +254,10 @@
c = c._superclass
return False
-def commonBaseclass(CLASS1, CLASS2):
- c = CLASS1
+def commonBaseclass(INSTANCE1, INSTANCE2):
+ c = INSTANCE1
while c is not None:
- if isSubclass(CLASS2, c):
+ if isSubclass(INSTANCE2, c):
return c
c = c._superclass
return None
Modified: pypy/branch/hl-backend/pypy/rpython/ootype/test/test_ooann.py
==============================================================================
--- pypy/branch/hl-backend/pypy/rpython/ootype/test/test_ooann.py (original)
+++ pypy/branch/hl-backend/pypy/rpython/ootype/test/test_ooann.py Wed Oct 12 18:34:39 2005
@@ -5,7 +5,7 @@
def test_simple_new():
- C = Class("test", None, {'a': Signed})
+ C = Instance("test", None, {'a': Signed})
def oof():
c = new(C)
@@ -18,7 +18,7 @@
assert s.knowntype == int
def test_simple_instanceof():
- C = Class("test", None, {'a': Signed})
+ C = Instance("test", None, {'a': Signed})
def oof():
c = new(C)
@@ -31,20 +31,69 @@
assert s.knowntype == bool
def test_simple_null():
- C = Class("test", None, {'a': Signed})
+ I = Instance("test", None, {'a': Signed})
def oof():
- c = null(C)
- return c
+ i = null(I)
+ return i
+
+ a = RPythonAnnotator()
+ s = a.build_types(oof, [])
+ #a.translator.view()
+
+ assert s == annmodel.SomeOOInstance(I)
+
+def test_simple_classof():
+ I = Instance("test", None, {'a': Signed})
+
+ def oof():
+ i = new(I)
+ return classof(i)
+
+ a = RPythonAnnotator()
+ s = a.build_types(oof, [])
+ #a.translator.view()
+
+ assert s == annmodel.SomeOOClass(I)
+
+def test_simple_runtimenew():
+ I = Instance("test", None, {'a': Signed})
+
+ def oof():
+ i = new(I)
+ c = classof(i)
+ i2 = runtimenew(c)
+ return i2
a = RPythonAnnotator()
s = a.build_types(oof, [])
#a.translator.view()
- assert s == annmodel.SomeRef(C)
+ assert s == annmodel.SomeOOInstance(I)
+
+def test_complex_runtimenew():
+ I = Instance("test", None, {'a': Signed})
+ J = Instance("test2", I, {'b': Signed})
+ K = Instance("test2", I, {'b': Signed})
+
+ def oof(x):
+ k = new(K)
+ j = new(J)
+ if x:
+ c = classof(k)
+ else:
+ c = classof(j)
+ i = runtimenew(c)
+ return i
+
+ a = RPythonAnnotator()
+ s = a.build_types(oof, [bool])
+ #a.translator.view()
+
+ assert s == annmodel.SomeOOInstance(I)
def test_method():
- C = Class("test", None, {"a": (Signed, 3)})
+ C = Instance("test", None, {"a": (Signed, 3)})
M = Meth([C], Signed)
def m_(self, other):
@@ -64,9 +113,9 @@
assert s.knowntype == int
def test_unionof():
- C1 = Class("C1", None)
- C2 = Class("C2", C1)
- C3 = Class("C3", C1)
+ C1 = Instance("C1", None)
+ C2 = Instance("C2", C1)
+ C3 = Instance("C3", C1)
def oof(f):
if f:
@@ -79,7 +128,7 @@
s = a.build_types(oof, [bool])
#a.translator.view()
- assert s == annmodel.SomeRef(C1)
+ assert s == annmodel.SomeOOInstance(C1)
def test_static_method():
F = StaticMethod([Signed, Signed], Signed)
@@ -94,5 +143,5 @@
s = a.build_types(oof, [])
#a.translator.view()
- assert s.knowntype = int
+ assert s.knowntype == int
Modified: pypy/branch/hl-backend/pypy/rpython/ootype/test/test_ootype.py
==============================================================================
--- pypy/branch/hl-backend/pypy/rpython/ootype/test/test_ootype.py (original)
+++ pypy/branch/hl-backend/pypy/rpython/ootype/test/test_ootype.py Wed Oct 12 18:34:39 2005
@@ -9,31 +9,52 @@
def m_(self, b):
return self.a + b
m = meth(M, _name="m", _callable=m_)
- C = Class("test", None, {"a": Signed}, {"m": m})
- assert type(hash(C)) == int
+ I = Instance("test", None, {"a": Signed}, {"m": m})
+ assert type(hash(I)) == int
def test_simple_class():
- C = Class("test", None, {"a": Signed})
+ I = Instance("test", None, {"a": Signed})
+ i = new(I)
- c = new(C)
- assert typeOf(c) == C
-
- py.test.raises(TypeError, "c.z")
- py.test.raises(TypeError, "c.a = 3.0")
+ py.test.raises(TypeError, "i.z")
+ py.test.raises(TypeError, "i.a = 3.0")
+
+ i.a = 3
+ assert i.a == 3
+
+def test_runtime_instanciation():
+ I = Instance("test", None, {"a": Signed})
+ c = runtimeClass(I)
+ i = runtimenew(c)
- c.a = 3
- assert c.a == 3
+ assert typeOf(i) == I
+ assert typeOf(c) == Class
+def test_classof():
+ I = Instance("test", None, {"a": Signed})
+ c = runtimeClass(I)
+ i = new(I)
+
+ assert classof(i) == c
+
+ j = new(I)
+
+ assert classof(i) is classof(j)
+ I2 = Instance("test2", I, {"b": Signed})
+ i2 = new(I2)
+ assert classof(i2) is not classof(i)
+ assert classof(i2) != classof(i)
+
def test_simple_default_class():
- C = Class("test", None, {"a": (Signed, 3)})
+ I = Instance("test", None, {"a": (Signed, 3)})
+ i = new(I)
- c = new(C)
- assert c.a == 3
+ assert i.a == 3
- py.test.raises(TypeError, "Class('test', None, {'a': (Signed, 3.0)})")
+ py.test.raises(TypeError, "Instance('test', None, {'a': (Signed, 3.0)})")
def test_simple_null():
- C = Class("test", None, {"a": Signed})
+ C = Instance("test", None, {"a": Signed})
c = null(C)
assert typeOf(c) == C
@@ -41,9 +62,9 @@
py.test.raises(RuntimeError, "c.a")
def test_simple_class_field():
- C = Class("test", None, {})
+ C = Instance("test", None, {})
- D = Class("test2", None, {"a": C})
+ D = Instance("test2", None, {"a": C})
d = new(D)
assert typeOf(d.a) == C
@@ -51,7 +72,7 @@
assert d.a == null(C)
def test_simple_recursive_class():
- C = Class("test", None, {})
+ C = Instance("test", None, {})
addFields(C, {"inst": C})
@@ -59,16 +80,16 @@
assert c.inst == null(C)
def test_simple_super():
- C = Class("test", None, {"a": (Signed, 3)})
- D = Class("test2", C, {})
+ C = Instance("test", None, {"a": (Signed, 3)})
+ D = Instance("test2", C, {})
d = new(D)
assert d.a == 3
def test_simple_field_shadowing():
- C = Class("test", None, {"a": (Signed, 3)})
+ C = Instance("test", None, {"a": (Signed, 3)})
- py.test.raises(TypeError, """D = Class("test2", C, {"a": (Signed, 3)})""")
+ py.test.raises(TypeError, """D = Instance("test2", C, {"a": (Signed, 3)})""")
def test_simple_static_method():
F = StaticMethod([Signed, Signed], Signed)
@@ -97,7 +118,7 @@
return self.a + b
m = meth(M, _name="m", _callable=m_)
- C = Class("test", None, {"a": (Signed, 2)}, {"m": m})
+ C = Instance("test", None, {"a": (Signed, 2)}, {"m": m})
c = new(C)
assert c.m(3) == 5
@@ -112,12 +133,12 @@
return self.a + b
m = meth(M, _name="m", _callable=m_)
- py.test.raises(TypeError, """Class("test", None, {"a": M})""")
+ py.test.raises(TypeError, """Instance("test", None, {"a": M})""")
- py.test.raises(TypeError, """Class("test", None, {"m": Signed}, {"m":m})""")
+ py.test.raises(TypeError, """Instance("test", None, {"m": Signed}, {"m":m})""")
def test_simple_recursive_meth():
- C = Class("test", None, {"a": (Signed, 3)})
+ C = Instance("test", None, {"a": (Signed, 3)})
M = Meth([C], Signed)
def m_(self, other):
@@ -130,7 +151,7 @@
assert c.m(c) == 6
def test_explicit_name_clash():
- C = Class("test", None, {})
+ C = Instance("test", None, {})
addFields(C, {"a": (Signed, 3)})
@@ -144,8 +165,8 @@
py.test.raises(TypeError, """addFields(C, {"b": Signed})""")
def test_instanceof():
- C = Class("test", None, {})
- D = Class("test2", C, {})
+ C = Instance("test", None, {})
+ D = Instance("test2", C, {})
c = new(C)
d = new(D)
assert instanceof(c, C)
@@ -154,7 +175,7 @@
assert instanceof(d, C)
def test_superclass_meth_lookup():
- C = Class("test", None, {"a": (Signed, 3)})
+ C = Instance("test", None, {"a": (Signed, 3)})
M = Meth([C], Signed)
def m_(self, other):
@@ -163,7 +184,7 @@
addMethods(C, {"m": m})
- D = Class("test2", C, {})
+ D = Instance("test2", C, {})
d = new(D)
assert d.m(d) == 6
@@ -177,10 +198,10 @@
assert d.m(d) == 9
def test_isSubclass():
- A = Class("A", None)
- B = Class("B", A)
- C = Class("C", A)
- D = Class("D", C)
+ A = Instance("A", None)
+ B = Instance("B", A)
+ C = Instance("C", A)
+ D = Instance("D", C)
assert isSubclass(A, A)
assert isSubclass(B, A)
@@ -192,12 +213,12 @@
assert not isSubclass(D, B)
def test_commonBaseclass():
- A = Class("A", None)
- B = Class("B", A)
- C = Class("C", A)
- D = Class("D", C)
- E = Class("E", None)
- F = Class("F", E)
+ A = Instance("A", None)
+ B = Instance("B", A)
+ C = Instance("C", A)
+ D = Instance("D", C)
+ E = Instance("E", None)
+ F = Instance("F", E)
assert commonBaseclass(A, A) == A
assert commonBaseclass(A, B) == A
More information about the Pypy-commit
mailing list