On Sep 17, 2008, at 3:57 AM, Dag Sverre Seljebotn wrote:

> According to the buffer PEP, __getbuffer__ should raise a BufferError
> under certain circumstances. This is not present in older versions of
> Python. Backport/emulate or not? Any good ideas for how it should
> happen? (I'm blank when it comes to both builtins and creating  
> exception
> types.) One option could be to simply make BufferError be a ValueError
> in Python 2.5-; still, the main question I guess is whether we import
> BufferError into the Cython builtin scope.

Yes, I think we should.

Like you said, the easy way is to #define it to be ValueError for  
Python 2.5-. The other way would be to fill it in during  
initialization with a manually created class (see  
ExprNodes.ClassNode). Care must be taken to have a globally unique  
BufferError, so perhaps it should be injected into (and an attempt to  
looked up from) the __builtin__ module.

> Slightly related, look at this code in Symtab.py:
> def declare_builtin(self, name, pos):
>     if not hasattr(__builtin__, name):
>
> If I'm not entirely wrong, this means that BufferError (and other new
> builtin symbols) will be available only if you run Cython under Python
> 2.6+. I find the fact that results of a compilation depends on the
> Python version used for running Cython somewhat disturbing. Should
> perhaps a literal list of accepted Cython builtins be present in
> Symtab.py instead? (Or couple it to Builtins.py somehow?)

I think maintaining such a list would be less elegant than looking  
them up at runtime, especially as it is fairly stable and  
monotonically increasing. If one wants to use the code with, say,  
Python 2.3, then one simply has to avoid using newer symbols in ones  
code (just as with Python), and it is easy to check (just compile  
with Python 2.3). This allows people to write code with newer  
builtins if one wants without having to maintain a list of when every  
symbol was introduced.

- Robert
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to