2010/11/8 Stefan Behnel <[email protected]>: > Darren Dale, 08.11.2010 15:34: >> Python-2.6 extended the definition of property to include getter, >> setter, and deleter methods that can be used as decorators. This >> allows a really nice pattern for declaring properties without >> populating the namespace with a bunch of private methods: >> >> class Foo(object): >> >> _bar = None >> �...@property >> def bar(self): >> return self._bar >> �[email protected] >> def bar(self, val): >> self._bar = val >> >> What happens is @bar.setter makes a copy of bar, updates the copy to >> use the decorated method as the setter, and returns the copy, which is >> then bound to the name of the decorated function. The decorated >> function has to be called bar, so that the updated copy is bound to >> bar, replacing the original. >> >> Attempting to cythonize this example yields an error: >> >> $ python setup.py build_ext --inplace >> running build_ext >> cythoning test_property.pyx to test_property.c >> >> Error converting Pyrex file to C: >> ------------------------------------------------------------ >> ... >> _bar = None >> �...@property >> def bar(self): >> return self._bar >> �[email protected] >> def bar(self, val): >> ^ >> ------------------------------------------------------------ >> >> /Users/darren/temp/test/test_property.pyx:11:4: 'bar' already declared >> >> Would it be possible for Cython to support this pattern? > > The problem is not the property behaviour, it's the mapping from a Python > function/method to a C function, which must have a unique name. Currently, > functions are unique within one namespace, be it the module namespace or a > class body namespace. They are actually looked up statically, not > dynamically in definition order, so the fix is not as easy as adding a > counted ID to the C-level name. >
Is not it safe to add ID to C-function in pure python class scope? I see problem in module scope when it turns functions into list of methoddef that are passed to PyModule_Init. vitja. _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
