[pypy-commit] pypy reflex-support: namespaces in namespaces and inner classes

wlav noreply at buildbot.pypy.org
Tue May 31 02:49:01 CEST 2011


Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: reflex-support
Changeset: r44606:97a909c6dfa8
Date: 2011-05-30 17:59 -0700
http://bitbucket.org/pypy/pypy/changeset/97a909c6dfa8/

Log:	namespaces in namespaces and inner classes

diff --git a/pypy/module/cppyy/pythonify.py b/pypy/module/cppyy/pythonify.py
--- a/pypy/module/cppyy/pythonify.py
+++ b/pypy/module/cppyy/pythonify.py
@@ -53,7 +53,7 @@
     return method
 
 
-def __ns_getattr__(self, attr):
+def __innercpp_getattr__(self, attr):
     try:
         cppclass = get_cppitem(attr, self.__name__)
         self.__dict__[attr] = cppclass
@@ -61,7 +61,7 @@
     except TypeError, e:
         import traceback
         traceback.print_exc()
-        raise AttributeError("namespace object has no attribute '%s'" % attr)
+        raise AttributeError("%s object has no attribute '%s'" % (self,attr))
 
 
 def make_cppnamespace(name, cppns):
@@ -73,7 +73,8 @@
         d[f] = make_static_function(cppns, f, cppol.get_returntype())
 
     # create a meta class to allow properties (for static data write access)
-    metans = type(CppyyNamespace)(name+'_meta', (type(type),), {"__getattr__" : __ns_getattr__})
+    metans = type(CppyyNamespace)(name+'_meta', (type(type),),
+                                  {"__getattr__" : __innercpp_getattr__})
 
     # add all data members to the dictionary of the class to be created, and
     # static ones also to the meta class (needed for property setters)
@@ -107,7 +108,8 @@
 
     # create a meta class to allow properties (for static data write access)
     metabases = tuple([type(base) for base in bases])
-    metacpp = type(CppyyClass)(name+'_meta', metabases, {})
+    metacpp = type(CppyyClass)(name+'_meta', metabases,
+                               {"__getattr__" : __innercpp_getattr__})
 
     # add all data members to the dictionary of the class to be created, and
     # static ones also to the meta class (needed for property setters)
@@ -143,9 +145,9 @@
 
     cppitem = cppyy._type_byname(fullname)
     if cppitem.is_namespace():
-        return make_cppnamespace(name, cppitem)
+        return make_cppnamespace(fullname, cppitem)
     else:
-        return make_cppclass(name, cppitem)
+        return make_cppclass(fullname, cppitem)
 get_cppclass = get_cppitem         # TODO: restrict to classes only (?)
 
 
diff --git a/pypy/module/cppyy/test/test_advancedcpp.py b/pypy/module/cppyy/test/test_advancedcpp.py
--- a/pypy/module/cppyy/test/test_advancedcpp.py
+++ b/pypy/module/cppyy/test/test_advancedcpp.py
@@ -44,16 +44,21 @@
 
         import cppyy
 
+# TODO: have Reflex add the globals to the dictionary ...
 #        assert cppyy.gbl.a_ns.g_a                           == 11
         assert cppyy.gbl.a_ns.b_class.s_b                   == 22
         assert cppyy.gbl.a_ns.b_class().m_b                 == -2
-#        assert cppyy.gbl.a_ns.b_class.c_class.s_c           == 33
-#        assert cppyy.gbl.a_ns.b_class.c_class().m_c         == -3
+        assert cppyy.gbl.a_ns.b_class.c_class.s_c           == 33
+        assert cppyy.gbl.a_ns.b_class.c_class().m_c         == -3
 #        assert cppyy.gbl.a_ns.d_ns.g_d                      == 44
-#        assert cppyy.gbl.a_ns.d_ns.e_class.s_e              == 55
-#        assert cppyy.gbl.a_ns.d_ns.e_class().m_e            == -5
-#        assert cppyy.gbl.a_ns.d_ns.e_class.f_class.s_f      == 66
-#        assert cppyy.gbl.a_ns.d_ns.e_class.f_class().m_f    == -6
+        assert cppyy.gbl.a_ns.d_ns.e_class.s_e              == 55
+        assert cppyy.gbl.a_ns.d_ns.e_class().m_e            == -5
+        assert cppyy.gbl.a_ns.d_ns.e_class.f_class.s_f      == 66
+        assert cppyy.gbl.a_ns.d_ns.e_class.f_class().m_f    == -6
 
         assert cppyy.gbl.a_ns      is cppyy.gbl.a_ns
         assert cppyy.gbl.a_ns.d_ns is cppyy.gbl.a_ns.d_ns
+
+        assert cppyy.gbl.a_ns.b_class              is cppyy.gbl.a_ns.b_class
+        assert cppyy.gbl.a_ns.d_ns.e_class         is cppyy.gbl.a_ns.d_ns.e_class
+        assert cppyy.gbl.a_ns.d_ns.e_class.f_class is cppyy.gbl.a_ns.d_ns.e_class.f_class


More information about the pypy-commit mailing list