On Jul 7, 2009, at 5:59 AM, Dag Sverre Seljebotn wrote:

> Stefan Behnel wrote:
>> Dag Sverre Seljebotn wrote:
>>> Stefan Behnel wrote:
>>>> Dag Sverre Seljebotn wrote:
>>>>> a) Auto-cimport (if a directive is set, which defaults to on?).  
>>>>> I.e. if
>>>>> you do a Python import, and a pxd file can be found, a cimport  
>>>>> is done
>>>>> automatically.
>>>> +0.7 given that this may really have a performance impact, as  
>>>> Robert
>>>> stated. There should at least be a cache for the standard  
>>>> include path that
>>>> survives multiple compilations in one compiler run (another  
>>>> orthogonal
>>>> feature that would be nice for .pxd files in general).
>>> with cython.nopxd:
>>>      import mymodule
>>>
>>> ?
>>
>> -1
>>
>> Besides being the wrong way round (most Python modules do not have  
>> a .pxd
>> file), this is clearly something that Cython should handle behind the
>> scenes. User code shouldn't be impacted by it. If anything, a  
>> compiler
>> option would fit. But thinking about that now smells like a premature
>> optimisation to me.
>
> But (expert) users must have control and care about this, it cannot
> happen behind the scenes anyway! I.e. with no automatic cimport,  
> you can do
>
> import itertools
>
> ...
>
> itertools = None
> ...
>
> With auto cimport (like you seemed to want originally, at least for  
> the
> specific case of itertools) this is a syntax error.

I think it would be possible (though not trivial--cimports are  
necessarily resolved in the same stage as declaration analyses) to  
make it fall back to being a regular import (with a warning?) in this  
case.

> This early-binding is the big change in semantics; everything else is
> just details.

Exactly. For example, if I do

import math
print math.sin(foo()), math.sin(bar())

I should be doing an attribute lookup on math twice, just in case bar  
was defined as

def bar():
     import math
     math.sin = math.cos
     return 1

> But I think it makes sense to say that Cython does, for module-level
> imports at the top of the file, early bind them, as it is OK anyway  
> for
> 99% of the usecases (and a syntax error is raised anyway at  
> "itertool =
> None", which could say "you have to turn off auto-cimport").

I could live with this too.

- Robert

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

Reply via email to