Author: Ronan Lamy <[email protected]>
Branch: anntype2
Changeset: r80959:6ebeeb9aabc6
Date: 2015-11-25 15:22 +0000
http://bitbucket.org/pypy/pypy/changeset/6ebeeb9aabc6/
Log: Use ClassDescs instead of ClassDefs in our_issubclass()
diff --git a/rpython/annotator/classdesc.py b/rpython/annotator/classdesc.py
--- a/rpython/annotator/classdesc.py
+++ b/rpython/annotator/classdesc.py
@@ -258,8 +258,8 @@
yield self
self = self.basedef
- def issubclass(self, otherclsdef):
- return otherclsdef in self.parentdefs
+ def issubclass(self, other):
+ return self.classdesc.issubclass(other.classdesc)
def getallsubdefs(self):
pending = [self]
@@ -722,6 +722,9 @@
return True
return False
+ def issubclass(self, other):
+ return issubclass(self.pyobj, other.pyobj)
+
def lookup(self, name):
cdesc = self
while name not in cdesc.classdict:
diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py
--- a/rpython/annotator/model.py
+++ b/rpython/annotator/model.py
@@ -436,7 +436,7 @@
def __init__(self, classdef, can_be_None=False, flags={}):
self.classdef = classdef
- self.knowntype = classdef or object
+ self.knowntype = classdef.classdesc if classdef else None
self.can_be_None = can_be_None
self.flags = flags
diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py
--- a/rpython/annotator/unaryop.py
+++ b/rpython/annotator/unaryop.py
@@ -19,7 +19,7 @@
from rpython.annotator.binaryop import _clone ## XXX where to put this?
from rpython.annotator.binaryop import _dict_can_only_throw_keyerror
from rpython.annotator.binaryop import _dict_can_only_throw_nothing
-from rpython.annotator.classdesc import ClassDef
+from rpython.annotator.classdesc import ClassDesc
from rpython.annotator.model import AnnotatorError
from rpython.annotator.argument import simple_args, complex_args
@@ -38,27 +38,27 @@
return True
def classify(cls):
from rpython.rlib.rarithmetic import base_int
- if isinstance(cls, ClassDef):
- return 'def'
+ if isinstance(cls, ClassDesc):
+ return 'desc'
if cls.__module__ == '__builtin__' or issubclass(cls, base_int):
return 'builtin'
else:
return 'cls'
kind1 = classify(cls1)
kind2 = classify(cls2)
- if kind1 != 'def' and kind2 != 'def':
+ if kind1 != 'desc' and kind2 != 'desc':
return issubclass(cls1, cls2)
- if kind1 == 'builtin' and kind2 == 'def':
+ if kind1 == 'builtin' and kind2 == 'desc':
return False
- elif kind1 == 'def' and kind2 == 'builtin':
+ elif kind1 == 'desc' and kind2 == 'builtin':
return issubclass(object, cls2)
else:
- def toclassdef(kind, cls):
- if kind != 'def':
- return bk.getuniqueclassdef(cls)
+ def toclassdesc(kind, cls):
+ if kind != 'desc':
+ return bk.getdesc(cls)
else:
return cls
- return toclassdef(kind1, cls1).issubclass(toclassdef(kind2, cls2))
+ return toclassdesc(kind1, cls1).issubclass(toclassdesc(kind2, cls2))
def s_isinstance(annotator, s_obj, s_type, variables):
diff --git a/rpython/rlib/test/test_objectmodel.py
b/rpython/rlib/test/test_objectmodel.py
--- a/rpython/rlib/test/test_objectmodel.py
+++ b/rpython/rlib/test/test_objectmodel.py
@@ -113,11 +113,11 @@
Strange_def = a.bookkeeper.getuniqueclassdef(Strange)
graph = graphof(t, strange_key_eq)
- assert a.binding(graph.getargs()[0]).knowntype == Strange_def
+ assert a.binding(graph.getargs()[0]).classdef == Strange_def
assert a.binding(graph.getargs()[1]).knowntype == str
assert a.binding(graph.getargs()[2]).knowntype == str
graph = graphof(t, strange_key_hash)
- assert a.binding(graph.getargs()[0]).knowntype == Strange_def
+ assert a.binding(graph.getargs()[0]).classdef == Strange_def
assert a.binding(graph.getargs()[1]).knowntype == str
diff --git a/rpython/rtyper/test/test_llannotation.py
b/rpython/rtyper/test/test_llannotation.py
--- a/rpython/rtyper/test/test_llannotation.py
+++ b/rpython/rtyper/test/test_llannotation.py
@@ -15,6 +15,7 @@
def __init__(self, cls=C):
self.cls = cls
self.name = cls.__name__
+ self.classdesc = cls
def test_ll_to_annotation():
s_z = ll_to_annotation(lltype.Signed._defl())
diff --git a/rpython/rtyper/test/test_nongc.py
b/rpython/rtyper/test/test_nongc.py
--- a/rpython/rtyper/test/test_nongc.py
+++ b/rpython/rtyper/test/test_nongc.py
@@ -40,7 +40,7 @@
#does not raise:
s = a.build_types(f, [])
Adef = a.bookkeeper.getuniqueclassdef(A)
- assert s.knowntype == Adef
+ assert s.classdef == Adef
rtyper = RPythonTyper(a)
rtyper.specialize()
assert (Adef, 'raw') in rtyper.instance_reprs
@@ -59,7 +59,7 @@
s = a.build_types(f, [])
Adef = a.bookkeeper.getuniqueclassdef(A)
Bdef = a.bookkeeper.getuniqueclassdef(B)
- assert s.knowntype == Bdef
+ assert s.classdef == Bdef
rtyper = RPythonTyper(a)
rtyper.specialize()
assert (Adef, 'raw') in rtyper.instance_reprs
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit