[pypy-svn] r33770 - in pypy/dist/pypy/translator/cli: . test

antocuni at codespeak.net antocuni at codespeak.net
Thu Oct 26 14:50:44 CEST 2006


Author: antocuni
Date: Thu Oct 26 14:50:43 2006
New Revision: 33770

Modified:
   pypy/dist/pypy/translator/cli/dotnet.py
   pypy/dist/pypy/translator/cli/test/test_dotnet.py
Log:
bugfix. This is really a workaround, but should work well at least
with mscorlib, which is what we need now.



Modified: pypy/dist/pypy/translator/cli/dotnet.py
==============================================================================
--- pypy/dist/pypy/translator/cli/dotnet.py	(original)
+++ pypy/dist/pypy/translator/cli/dotnet.py	Thu Oct 26 14:50:43 2006
@@ -184,10 +184,22 @@
 
     def __getattr__(self, attr):
         from pypy.translator.cli.query import load_class_or_namespace
-        name = self.__fullname(attr)
-        load_class_or_namespace(name)
-        assert attr in self.__dict__
-        return getattr(self, attr)
+        # .NET namespace are not self-entities but just parts of the
+        # FullName of a class. This imply that there is no way ask
+        # .NET if a particular name is a namespace; there are many
+        # names that are clearly not namespaces such as im_self and
+        # _freeze_, but there is no general rule and we have to guess.
+        # For now, the heuristic simply check is the first char of the
+        # name is a UPPERCASE letter.
+        
+        if attr[0].isalpha() and attr[0] == attr[0].upper():
+            # we assume it's a class or namespace
+            name = self.__fullname(attr)
+            load_class_or_namespace(name)
+            assert attr in self.__dict__
+            return getattr(self, attr)
+        else:
+            raise AttributeError
 
 CLR = CliNamespace(None)
 

Modified: pypy/dist/pypy/translator/cli/test/test_dotnet.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/test_dotnet.py	(original)
+++ pypy/dist/pypy/translator/cli/test/test_dotnet.py	Thu Oct 26 14:50:43 2006
@@ -20,6 +20,14 @@
         assert isinstance(s, SomeCliClass)
         assert s.const is Math
 
+    def test_fullname(self):
+        def fn():
+            return CLR.System.Math
+        a = RPythonAnnotator()
+        s = a.build_types(fn, [])
+        assert isinstance(s, SomeCliClass)
+        assert s.const is Math
+
     def test_staticmeth(self):
         def fn():
             return Math.Abs



More information about the Pypy-commit mailing list