extended test case: test that common method forwarding patterns still work with the...
authorStefan Behnel <scoder@users.berlios.de>
Sun, 15 Aug 2010 19:43:21 +0000 (21:43 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Sun, 15 Aug 2010 19:43:21 +0000 (21:43 +0200)
tests/run/special_methods_T561.pyx

index 28253a353594a0b113791cd5758c2ccf96729613..e9bc8c746827b700b52cdcaf450d03eefaa0d8c7 100644 (file)
@@ -525,3 +525,31 @@ cdef class SetDelete:
 cdef class Long:
     def __long__(self):
         print "Long __long__"
+
+cdef class GetAttrGetItemRedirect:
+    """
+    >>> o = GetAttrGetItemRedirect()
+
+    >>> assert o.item == o['item']
+    >>> source, item_value = o.item
+    >>> assert source == 'item', source
+
+    >>> assert o['attr'] == o.attr
+    >>> source, attr_value = o['attr']
+    >>> assert source == 'attr', source
+
+    >>> assert item_value is attr_value, repr((item_value, attr_value))
+    """
+    cdef object obj
+    def __cinit__(self):
+        self.obj = object()
+
+    def __getattr__(self, name):
+        if name == 'item':
+            return self.__getitem__(name)
+        return ('attr', self.obj)
+
+    def __getitem__(self, key):
+        if key == 'attr':
+            return self.__getattr__(key)
+        return ('item', self.obj)