From: Stefan Behnel Date: Sun, 15 Aug 2010 19:43:21 +0000 (+0200) Subject: extended test case: test that common method forwarding patterns still work with the... X-Git-Tag: 0.13~14 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=c737211680f81546be76c9bb4406e9c6880739d1;p=cython.git extended test case: test that common method forwarding patterns still work with the new special method setup code --- diff --git a/tests/run/special_methods_T561.pyx b/tests/run/special_methods_T561.pyx index 28253a35..e9bc8c74 100644 --- a/tests/run/special_methods_T561.pyx +++ b/tests/run/special_methods_T561.pyx @@ -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)