Author: Ronan Lamy <[email protected]>
Branch: extregistry-refactor
Changeset: r62292:ffab5deb828b
Date: 2013-03-11 16:07 +0000
http://bitbucket.org/pypy/pypy/changeset/ffab5deb828b/
Log: Remove unused _condition_ handling in ExtRegistryEntry
diff --git a/rpython/rtyper/extregistry.py b/rpython/rtyper/extregistry.py
--- a/rpython/rtyper/extregistry.py
+++ b/rpython/rtyper/extregistry.py
@@ -22,17 +22,11 @@
for k in key:
selfcls._register(dict, k)
else:
- for basecls in selfcls.__mro__:
- if '_condition_' in basecls.__dict__:
- cond = basecls.__dict__['_condition_']
- break
- else:
- cond = None
try:
family = dict[key]
except KeyError:
family = dict[key] = ClassFamily()
- family.add(selfcls, cond)
+ family.add(selfcls)
def _register_value(selfcls, key):
selfcls._register(EXT_REGISTRY_BY_VALUE, key)
diff --git a/rpython/rtyper/test/test_extregistry.py
b/rpython/rtyper/test/test_extregistry.py
--- a/rpython/rtyper/test/test_extregistry.py
+++ b/rpython/rtyper/test/test_extregistry.py
@@ -9,7 +9,7 @@
from rpython.rtyper.test.test_llinterp import interpret
from rpython.rtyper.rmodel import Repr
-def dummy():
+def dummy():
raiseNameError
class Entry(ExtRegistryEntry):
@@ -20,7 +20,7 @@
def func():
x = dummy()
return x
-
+
a = RPythonAnnotator()
s = a.build_types(func, [])
assert isinstance(s, annmodel.SomeInteger)
@@ -38,20 +38,20 @@
def func():
x = dummy2()
return x
-
+
a = RPythonAnnotator()
s = a.build_types(func, [])
assert isinstance(s, annmodel.SomeInteger)
-
+
def test_register_type_with_callable():
class DummyType(object):
pass
-
+
dummy_type = DummyType()
-
+
def func():
return dummy_type
-
+
class Entry(ExtRegistryEntry):
_type_ = DummyType
def compute_annotation(self):
@@ -65,15 +65,15 @@
def test_register_metatype():
class MetaType(type):
pass
-
+
class RealClass(object):
__metaclass__ = MetaType
-
+
real_class = RealClass()
-
+
def func():
return real_class
-
+
class Entry(ExtRegistryEntry):
_metatype_ = MetaType
def compute_annotation(self):
@@ -88,13 +88,13 @@
def test_register_metatype_2():
class MetaType(type):
pass
-
+
class RealClass(object):
__metaclass__ = MetaType
-
+
def func(real_class):
return real_class
-
+
class Entry(ExtRegistryEntry):
_metatype_ = MetaType
def compute_annotation(self):
@@ -119,7 +119,7 @@
def func():
return dummy_func()
-
+
res = interpret(func, [])
assert res == 42
@@ -127,18 +127,18 @@
def test_register_type_with_get_repr():
class DummyClass(object):
pass
-
+
class SomeDummyObject(annmodel.SomeObject):
def rtyper_makerepr(self, rtyper):
entry = extregistry.lookup_type(self.knowntype)
return entry.get_repr(rtyper, self)
-
+
def rtyper_makekey( self ):
return self.__class__, self.knowntype
class DummyRepr(Repr):
lowleveltype = lltype.Signed
-
+
def convert_const(self, value):
return 42
@@ -155,14 +155,14 @@
return DummyRepr()
dummy_class = DummyClass()
-
+
def func():
return dummy_class
-
+
res = interpret(func, [])
-
+
assert res == 42
-
+
def test_register_unhashable():
lst1 = [5, 6]
lst2 = [5, 6]
@@ -178,26 +178,3 @@
_about_ = n1
assert isinstance(extregistry.lookup(n1), Entry)
assert isinstance(extregistry.lookup(n2), Entry)
-
-def test_condition():
- stuff = object()
- class Entry(ExtRegistryEntry):
- _about_ = stuff
- _condition_ = lambda n: n == 'yes'
- assert isinstance(extregistry.lookup(stuff, 'yes'), Entry)
- py.test.raises(KeyError, "extregistry.lookup(stuff, 'no')")
- py.test.raises(KeyError, "extregistry.lookup(stuff)")
-
- class Entry2(ExtRegistryEntry):
- _about_ = stuff
- assert isinstance(extregistry.lookup(stuff, 'yes'), Entry)
- assert isinstance(extregistry.lookup(stuff, 'no'), Entry2)
- assert isinstance(extregistry.lookup(stuff), Entry2)
-
- otherstuff = object()
- class Entry3(Entry):
- _about_ = otherstuff
- # _condition_ is inherited from Entry
- assert isinstance(extregistry.lookup(otherstuff, 'yes'), Entry3)
- py.test.raises(KeyError, "extregistry.lookup(otherstuff, 'no')")
- py.test.raises(KeyError, "extregistry.lookup(otherstuff)")
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit