[pypy-svn] r46061 - pypy/dist/pypy/rpython/numpy

simonb at codespeak.net simonb at codespeak.net
Mon Aug 27 20:58:44 CEST 2007


Author: simonb
Date: Mon Aug 27 20:58:44 2007
New Revision: 46061

Modified:
   pypy/dist/pypy/rpython/numpy/aarray.py
Log:
fix annotation of numpy attribute access

Modified: pypy/dist/pypy/rpython/numpy/aarray.py
==============================================================================
--- pypy/dist/pypy/rpython/numpy/aarray.py	(original)
+++ pypy/dist/pypy/rpython/numpy/aarray.py	Mon Aug 27 20:58:44 2007
@@ -1,7 +1,8 @@
 from pypy.rpython.extregistry import ExtRegistryEntry
 from pypy.annotation.pairtype import pairtype
 from pypy.annotation.model import SomeExternalObject, SomeList, SomeImpossibleValue
-from pypy.annotation.model import SomeObject, SomeInteger, SomeFloat, SomeString, SomeChar
+from pypy.annotation.model import SomeObject, SomeInteger, SomeFloat, SomeString, SomeChar,\
+    SomeGenericCallable
 from pypy.tool.error import AnnotatorError
 from pypy.rpython.lltypesystem import rffi
 from pypy.rlib import rarithmetic
@@ -46,6 +47,19 @@
     def get_item_type(self):
         return self.typecode_to_item[self.typecode]
 
+    def getattr(s_array, s_attr):
+        s = None
+        if s_attr.is_constant() and isinstance(s_attr.const, str):
+            attr = s_attr.const
+            if attr in ('transpose',):
+                s_result = SomeArray(s_array.knowntype, s_array.typecode, s_array.rank)
+                s = SomeGenericCallable([], s_result)
+            elif attr == 'shape':
+                s = SomeTuple([SomeInteger()]*s_array.rank)
+        if s is None:
+            return SomeObject()
+        return s
+
 class __extend__(pairtype(SomeArray, SomeArray)):
 
     def union((s_arr1, s_arr2)):
@@ -134,11 +148,6 @@
         from pypy.rpython.numpy.rarray import ArrayRepr
         return ArrayRepr(rtyper, s_array)
 
-    def get_field_annotation(self, knowntype, fieldname):
-        if fieldname in ('transpose',):
-            # XX knowntype is not enough to learn annotation from XX
-            return SomeArray()
-
 
 
 # Importing for side effect of registering types with extregistry



More information about the Pypy-commit mailing list