Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'level,': 0.07; 'suppose': 0.07; 'clean.': 0.09; 'function,': 0.09; 'mess': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'wrote': 0.14; 'function?': 0.16; 'imports': 0.16; 'modules.': 0.16; 'received:80.91.229.3': 0.16; 'received:97': 0.16; 'received:plane.gmane.org': 0.16; 'reusable': 0.16; 'subject:caught': 0.16; 'subject:import': 0.16; 'language': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'module': 0.19; 'basically': 0.19; 'finished': 0.19; 'pieces': 0.19; '>>>': 0.22; 'import': 0.22; 'putting': 0.22; 'module,': 0.24; 'mon,': 0.24; 'question': 0.24; 'gets': 0.27; 'header:X-Complaints-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'designer': 0.30; 'code': 0.31; '>>>>': 0.31; 'another': 0.32; 'worked': 0.33; 'subject:the': 0.34; 'could': 0.34; 'problem': 0.35; 'but': 0.35; 'responsible': 0.36; 'possible': 0.36; 'level': 0.37; 'sometimes': 0.38; 'depends': 0.38; 'nov': 0.38; 'needed': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'previous': 0.38; 'though,': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'called': 0.40; 'dave': 0.60; 'ian': 0.60; 'break': 0.61; 'first': 0.61; 'complete': 0.62; 'such': 0.63; '(that': 0.65; 'ending': 0.78; '"can\'t"': 0.84; 'angel': 0.91; 'exposing': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re: caught in the import web again Date: Tue, 18 Nov 2014 14:09:53 -0500 (EST) Organization: news.gmane.org References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 97.73.240.63 X-Newsreader: PiaoHong.Usenet.Client.VIP:1.65 X-Archive: encrypt X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1416337787 news.xs4all.nl 2882 [2001:888:2000:d::a6]:52120 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:81009 Ian Kelly Wrote in message: > On Mon, Nov 17, 2014 at 6:20 PM, Dave Angel wrote: >> Ian Kelly Wrote in message: >>> On Mon, Nov 17, 2014 at 3:17 PM, Dave Angel wrote: >> >>>> In a module that might get tangled in a cycle, avoid global code >>>> that depends on other modules. Instead of putting such >>>> initialization at top level, put inside a function that gets >>>> called after all suspect imports are completed. (That function >>>> has global keywords ). >>> >>> If the problem is that one of those modules would import the current >>> module, then "after all suspect imports are completed" basically means >>> after the current module has finished importing. So what would be >>> responsible for calling such a function? >>> >> >> If one builds a set of modules that cannot avoid recursive >> imports, then one can ask the code that imports it to make a call >> after importing. Or all that is needed to avoid exposing the mess >> is that the top level not be part of the loops. > > This would make the module less reusable though, since the first other > module to import it in one program might still be used in another > program but not be the first other module to import it. Or I suppose > for simplicity it could be required that all importers call the > initialization function, and have the function return immediately if > it's been called previously. However, I don't think there's any way to > do this without ending up with smelly code. > The smelly code happened when the designer "can't" break the cycle. I understood the question to be "then what." Two-stage initialization is sometimes "needed" in any language and I was just showing it's possible in Python. I once worked on (and then fixed) a build system that could not complete a build from clean. It needed some pieces from a previous build in order to get to the point where it was ready to build those pieces. Recursive depencies at compile and link time. -- DaveA