Robert Bradshaw wrote:
> 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
>
> On Jul 7, 2009, at 5:59 AM, Dag Sverre Seljebotn wrote:
>> 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.

I think we should only optimise imports that happen at the module level. If
the module is (re-)imported anywhere else, or the imported name is
reassigned anywhere in the module, this would simply disable the
optimisation. This is easy to check for. A warning would be OK in that
case, and I'm pretty sure users can live with this.

We'd have to rethink this restriction if we ever consider changing the
functionality of an imported module, but as long as it's really only an
optimisation, I'm fine with handling only the most simple and most common
case, and just make sure that we don't break things.

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

Reply via email to