[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [GMG-Devel] cyclic imports

From: Christopher Allan Webber
Subject: Re: [GMG-Devel] cyclic imports
Date: Fri, 14 Dec 2012 09:46:23 -0600
User-agent: mu4e 0.9.9-dev6; emacs

Well, the solution we often use is in the case of some awful cycle,
import inside the function:

def foo():
  import mediagoblin.would_cycle

I actually have no idea what the cost of doing imports like this is, but
we definitely love them it seems. ;)

We could refactor... but I'm hesitant to jump in and refactor like
crazy... that could be causing messes to save messes.

Here's an idea I had this morning... warning, it's crazy ("crazy" is the
word of the morning it seems):

#+BEGIN_SRC python
some_module = None

def blah_blah():

def _import_stragglers():
    Do any imports that would cause import cycles in this module, if we haven't

    import as some_module_tmp
    global some_module
    some_module_tmp = some_module

    import as another_module_tmp
    global another_module
    another_module_tmp = another_module


However that looks messy, and I can't think of any way to make it less
messy.  If only we had lisp macros! ;)  I don't know if it's necessary
either... I haven't profiled how long redundant inline imports are.

Otherwise, what's wrong with in-function imports?  They work :)

Sebastian Spaeth writes:

> Whenever I modify things, I have to fight cyclic imports in MediaGoblin. 
> This is an issue that we really need to think about. Consider this:
> I want to give better error message in the case of csrf failures. To do 
> so I modify
> GMG.meddlewares.csrf to return a
> 1) tools.response imports tools.template to get access to
>     render_template()
> 2) tools.template imports meddlewares.csrf to get access to
>     render_csrf_token().
> 3) meddlewares.csrf imports tools.response to get access to
>     render_error()
> 4) BANG BOOM CRASH. ImportError!
> How can we solve this issues in this specific and the general case? Here 
> I could imagine to solve/fix this by splitting CSRF into a 
> meddlewares.csrf (which does the checking) and a tools.csrf (which does 
> the actual rendering of the token). But that would split CSRF 
> functionality over 2 files. (we could also put it into tools.template 
> rather than tools.csrf).
> Sebastian
> _______________________________________________
> devel mailing list
> address@hidden

reply via email to

[Prev in Thread] Current Thread [Next in Thread]