On Friday, September 15, 2017 at 2:28:06 PM UTC-7, Travis Scrimshaw wrote:
>
>
> Why are you proposing local imports?  If python puts a performance penalty 
>> on them (in fact a significant performance penalty), they should be 
>> avoided, no?
>>
>> It is a relatively small penalty, so when it is not in a tight loop, it 
> is useful to break out of those cyclic imports (and has better locality of 
> reference).
>

For the most part, Python should be able to handle circular imports on the 
top-level. The obvious problems arise if we have

A:
from B import b

B:
from A import a


Normally, what should be OK is

A:
import B
def ...:
    B.b(bla)

B:
import A
def ...:
    A.a(bla)

So if you're finding you can't put a "from A import a" at the top-level and 
using it locally has noticeable cost (which can easily happen: imports have 
a significant cost, even for modules that are already present), then you 
could try to do a straight import and access the appropriate namespace. If 
that's a bunch of levels deep, you could try "import ..... as ..." at 
toplevel instead, so that there's a direct pointer to the relevant 
namespace (in case the multiple indirections still cause too much overhead).

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to