Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80995

Re: caught in the import web again

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <torriem+gmail@torriefamily.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.027
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'python,': 0.02; 'dependency': 0.09; 'instances.': 0.09; 'a),': 0.16; 'entirely.': 0.16; 'factory': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'imported.': 0.16; 'subject:caught': 0.16; 'subject:import': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'typing': 0.19; 'later': 0.20; 'header:User-Agent:1': 0.23; 'circular': 0.24; 'frameworks': 0.24; 'connected': 0.24; 'world,': 0.26; 'header:In-Reply-To:1': 0.27; 'testing': 0.29; "doesn't": 0.30; '(like': 0.30; '(which': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'class': 0.32; 'interface': 0.32; 'third': 0.33; 'subject:the': 0.34; 'could': 0.34; 'problem': 0.35; 'test': 0.35; 'there': 0.35; 'c++': 0.36; 'instances': 0.36; 'done': 0.36; 'method': 0.36; 'example,': 0.37; 'throughout': 0.37; 'so,': 0.37; 'turn': 0.37; 'message-id:@gmail.com': 0.38; 'depends': 0.38; 'to:addr:python-list': 0.38; 'issue': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'problems.': 0.60; 'most': 0.60; 'break': 0.61; 'simply': 0.61; 'more': 0.64; 'here': 0.66; 'design.': 0.68; 'easier,': 0.84; 'nicely.': 0.84; 'eliminates': 0.91
X-Virus-Scanned amavisd-new at torriefamily.org
Date Tue, 18 Nov 2014 00:00:42 -0700
From Michael Torrie <torriem@gmail.com>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131118 Thunderbird/17.0.11
MIME-Version 1.0
To python-list@python.org
Subject Re: caught in the import web again
References <m48lfh$n88$1@dont-email.me> <mailman.15871.1416122062.18130.python-list@python.org> <m49omd$924$1@dont-email.me> <546a7aa0$0$12995$c3e8da3$5496439d@news.astraweb.com>
In-Reply-To <546a7aa0$0$12995$c3e8da3$5496439d@news.astraweb.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.15970.1416294062.18130.python-list@python.org> (permalink)
Lines 26
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1416294062 news.xs4all.nl 2878 [2001:888:2000:d::a6]:59694
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:80995

Show key headers only | View raw


On 11/17/2014 03:45 PM, Steven D'Aprano wrote:

> Circular dependencies are not just a problem in Python, they are a problem
> throughout most of software design.

Personally I find that duck typing eliminates a lot of the circular
dependency problems.  Class A doesn't necessarily have to know about
Class B to work with instances of Class B.  All that has to be known is
what methods are going to be available on those instances.  The
interface pattern can help here if you wanted a bit more safety (like
what Zope provides).  Either way it breaks up the dependency cycle nicely.

If Class A needs to instantiate instances of Class B (which depends on
Class A), then it could call a factory method to do so, perhaps set up
by a third party after both modules have been imported.

There are lots of methods of avoiding the issue entirely.

In the C or C++ world, I find that signalling frameworks can also be
used to break a dependency cycle.  For example, if Class A needs to call
a method on an instance of Class B (which in turn depends on Class A),
that could be done instead as a signal, which is later connected to
Class B's method after everything is successfully instantiated.  Also
makes testing a bit easier, because you can simply hook up the signals
to a test harness.

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

caught in the import web again "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2014-11-15 22:52 +0000
  Re: caught in the import web again Ben Finney <ben+python@benfinney.id.au> - 2014-11-16 10:43 +1100
  Re: caught in the import web again Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-16 01:11 +0000
  Re: caught in the import web again dieter <dieter@handshake.de> - 2014-11-16 08:14 +0100
    Re: caught in the import web again "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2014-11-16 08:53 +0000
      Re: caught in the import web again Chris Angelico <rosuav@gmail.com> - 2014-11-16 20:20 +1100
      Re: caught in the import web again dieter <dieter@handshake.de> - 2014-11-17 08:08 +0100
        Re: caught in the import web again "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2014-11-17 20:07 +0000
          Re: caught in the import web again Dave Angel <davea@davea.name> - 2014-11-17 17:17 -0500
          Re: caught in the import web again Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-17 15:52 -0700
          Re: caught in the import web again Dave Angel <davea@davea.name> - 2014-11-17 20:20 -0500
          Re: caught in the import web again Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-18 08:28 -0700
          Re: caught in the import web again Dave Angel <davea@davea.name> - 2014-11-18 14:09 -0500
          Re: caught in the import web again Chris Angelico <rosuav@gmail.com> - 2014-11-19 07:18 +1100
          Re: caught in the import web again Dave Angel <davea@davea.name> - 2014-11-18 17:58 -0500
      Re: caught in the import web again Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-18 09:45 +1100
        Re: caught in the import web again Rick Johnson <rantingrickjohnson@gmail.com> - 2014-11-17 18:17 -0800
          Re: caught in the import web again Chris Angelico <rosuav@gmail.com> - 2014-11-18 13:25 +1100
          Re: caught in the import web again Steven D'Aprano <steve@pearwood.info> - 2014-11-18 07:13 +0000
        Re: caught in the import web again Michael Torrie <torriem@gmail.com> - 2014-11-18 00:00 -0700
          Re: caught in the import web again "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2014-11-18 09:13 +0000

csiph-web