[pypy-commit] pypy SpecialisedTuples: (mwp) add tests and code to generate name of each specialised class from its element types

mwp noreply at buildbot.pypy.org
Thu Nov 10 10:47:56 CET 2011


Author: Mark Pearse <mark.pearse at skynet.be>
Branch: SpecialisedTuples
Changeset: r49108:7a225189e654
Date: 2011-11-07 20:03 +0100
http://bitbucket.org/pypy/pypy/changeset/7a225189e654/

Log:	(mwp) add tests and code to generate name of each specialised class
	from its element types

diff --git a/pypy/objspace/std/specialisedtupleobject.py b/pypy/objspace/std/specialisedtupleobject.py
--- a/pypy/objspace/std/specialisedtupleobject.py
+++ b/pypy/objspace/std/specialisedtupleobject.py
@@ -61,7 +61,7 @@
         return tuple(self.tolist)
                         
 
-def make_specialised_class(class_name, typelist):
+def make_specialised_class(typelist):
     iter_n = unrolling_iterable(range(len(typelist)))
     class cls(W_SpecialisedTupleObject):
         def __init__(self, space, *values):
@@ -122,16 +122,16 @@
                     return self.space.wrap(getattr(self, 'value%s' % i))
             raise IndexError
 
-    cls.__name__ = class_name      
+    cls.__name__ = 'W_SpecialisedTupleObject' + ''.join([t.__name__.capitalize() for t in typelist])      
     _specialisations.append((cls,typelist))
     return cls
     
     
-W_SpecialisedTupleObjectIntInt     = make_specialised_class('W_SpecialisedTupleObjectIntInt',     (int,int))
-W_SpecialisedTupleObjectIntIntInt  = make_specialised_class('W_SpecialisedTupleObjectFloatFloat', (int,int,int))
-W_SpecialisedTupleObjectFloatFloat = make_specialised_class('W_SpecialisedTupleObjectFloatFloat', (float,float))
-W_SpecialisedTupleObjectStrStr     = make_specialised_class('W_SpecialisedTupleObjectStrStr',     (str, str))
-W_SpecialisedTupleObjectIntFloatStr= make_specialised_class('W_SpecialisedTupleObjectStrStr',     (int, float, str))
+W_SpecialisedTupleObjectIntInt     = make_specialised_class((int,int))
+W_SpecialisedTupleObjectIntIntInt  = make_specialised_class((int,int,int))
+W_SpecialisedTupleObjectFloatFloat = make_specialised_class((float,float))
+W_SpecialisedTupleObjectStrStr     = make_specialised_class((str, str))
+W_SpecialisedTupleObjectIntFloatStr= make_specialised_class((int, float, str))
 
 registerimplementation(W_SpecialisedTupleObject)
 
diff --git a/pypy/objspace/std/test/test_specialisedtupleobject.py b/pypy/objspace/std/test/test_specialisedtupleobject.py
--- a/pypy/objspace/std/test/test_specialisedtupleobject.py
+++ b/pypy/objspace/std/test/test_specialisedtupleobject.py
@@ -20,6 +20,10 @@
         w_tuple = self.space.newtuple([self.space.wrap({})])
         assert not isinstance(w_tuple, W_SpecialisedTupleObject)
         
+    def test_specialisedtupleclassname(self):
+        w_tuple = self.space.newtuple([self.space.wrap(1), self.space.wrap(2)])
+        assert w_tuple.__class__.__name__ == 'W_SpecialisedTupleObjectIntInt'
+        
     def test_hash_against_normal_tuple(self):
         normalspace = gettestobjspace(**{"objspace.std.withspecialisedtuple": False})
         specialisedspace = gettestobjspace(**{"objspace.std.withspecialisedtuple": True})


More information about the pypy-commit mailing list