On Oct 31, 2008, at 10:58 AM, Robert Bradshaw wrote:

> On Oct 31, 2008, at 10:46 AM, Stephane DROUARD wrote:
>
>> Robert Bradshaw wrote:
>>
>>>> In the documentation it is written that Cython defaults to the
>>>> built-in scope when it can't determine the scope of a variable,
>>>> which is different from Python, which defaults to the module scope.
>>>
>>> The documentation needs to be fixed then. If the scope of a variable
>>> can't be determined, then it actually raises a compile-time error.
>>
>> No, the example given in the documentation does not generate a
>> compile-time
>> error.
>>
>> foo.py:
>> print __name__
>>
>> But under Python it returns "foo", "__builtin__" when cython'ized.
>>
>> As the documentation specifies, this can be fixed by:
>>
>> foo.py:
>> global __name__
>> print __name__
>>
>> Then both return "foo".
>
> Ah, good catch. Cython (and, incidentally I) didn't know that
> __name__ is an already declared module-level variable, hence it
> looked it up as a builtin (and found it there, so no error). This is
> easily fixed by always having __name__ in the module namespace (what
> other magic variables are there?)

To clarify, other than these (thanks for the list Lisandro) the only  
time this can cause issues is if one manually adds names to the  
module externally, or if one uses "import *" to overwrite a builtin.

- Robert


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

Reply via email to