Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

They are relatively good but absolutely terrible. -- Alan Kay, commenting on Apollos


devel / comp.lang.python / Re: Cyclic imports

SubjectAuthor
o Re: Cyclic importsDan Stromberg

1
Re: Cyclic imports

<mailman.442.1629585334.4164.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=14703&group=comp.lang.python#14703

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: drsali...@gmail.com (Dan Stromberg)
Newsgroups: comp.lang.python
Subject: Re: Cyclic imports
Date: Sat, 21 Aug 2021 15:35:21 -0700
Lines: 22
Message-ID: <mailman.442.1629585334.4164.python-list@python.org>
References: <CAGGBd_qevXB-gk2AfhjJKt-hABaQSs+x3Bo2okNqN2+Go=hrfQ@mail.gmail.com>
<11811693.O9o76ZdvQC@varric.chelsea.private>
<CAPTjJmpy7-KFyq-upY2J=scJBq32MeYMPQM0tDkZEJBgnrmKaQ@mail.gmail.com>
<CAGGBd_rA=6EQJCZs63uCg37h1i9RogbhaeFg3C=viFRpxMHKhg@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de n0k8V+YEHZzJXgAT50naxwTJPopoFuCF4GTBp96B/Mig==
Return-Path: <drsalists@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=TP3Qg3cS;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '17,': 0.03; 'usage': 0.05;
'angelico': 0.09; 'ast': 0.09; 'aug': 0.09; 'cc:addr:python-list':
0.09; 'module.': 0.09; 'pypi,': 0.09; 'looks': 0.11; 'import':
0.14; '"import': 0.16; '(note': 0.16; 'cc:name:python list': 0.16;
'from:addr:drsalists': 0.16; 'from:name:dan stromberg': 0.16;
'received:209.85.217': 0.16; 'wrote:': 0.16; 'that.': 0.16;
'tue,': 0.18; 'cc:addr:python.org': 0.19; "i've": 0.22; 'run':
0.24; 'code': 0.24; 'anything': 0.24; 'thanks!': 0.25; 'chris':
0.26; 'cc:2**0': 0.27; 'output': 0.28; 'message-
id:@mail.gmail.com': 0.33; 'using': 0.33; 'header:In-Reply-To:1':
0.33; 'received:google.com': 0.34; 'missing': 0.35;
'from:addr:gmail.com': 0.35; 'inside': 0.37; 'two': 0.37;
'handle': 0.37; 'received:209.85': 0.38; "it's": 0.38;
'something': 0.38; 'received:209': 0.38; 'put': 0.39; 'main':
0.40; 'example': 0.40; 'test': 0.40; 'pretty': 0.40; "skip:' 20":
0.40; 'detected': 0.65; 'longer': 0.72; 'easy': 0.75; '2021':
0.84; 'bar,': 0.84; 'imports': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to
:cc; bh=Ws2p2IiOXmj6etMUuDpOUYQWFqDGZZGqbThCwmoNl+U=;
b=TP3Qg3cSx7GcpS9WmS3j3hFvMRyWI1ohY4nWCLwXbU6Wr5lDRyC3s+ZDSG2q7HLelB
TT8XZHNGLwhWvLj2V/HBXpK8brDuv26AEj65XpWlr2QHX3Ha1W2n52e0E0KTK1v1+2qM
+o4X/LHE5i+Qz79IJkqUCKitcXxMcswZ8lXKXbKmMy3hWbABuLmYq6W/f7RfsTqb1CJB
Ngydp66jtpEi506fCo9xj6wqVq+qZBonR1tHD+iLmN+jKMebAqEGeFkfk3A2P1Xj23q4
V/avRHVKxlQXE+SWa7ZMZON+ZV9sMUuntMNuNVArtFT1XXD8L554M6vwqJubB0Kfdvji
F2Kg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to:cc;
bh=Ws2p2IiOXmj6etMUuDpOUYQWFqDGZZGqbThCwmoNl+U=;
b=fKQ/ZgXry4qxgRtP3HDcWmTqUZ8yvUEm64D58QmVxXVs6EWDFnMTFeTXABfSFPihcE
sURiTC+GYKghSjrHK1IzsowBuAmxjyRNab5PLZGSW/ADQuHJhgcsP0LRlbu4d3bmZI/g
mpltIOoJh33pLiRskuZjgH4UslQ47InAIkdcOW4YT7esI8voEcm4xTjgSv/k2WC6tWxd
C+VBaE3DP8FUgHZcGDZJLLaIuZ+8qj1iH36i9ebeEfxAO72q4MIIfUYoowt+ASDXhyK9
OUhpKn4hzcZUvbpWcmWNs7YmDEC9GAe8ylSEqiHtfz8pLb1TNST9MByRJAsP8j9a3bkH
C72A==
X-Gm-Message-State: AOAM530gSuyl4j4gOLGmDu9Y/E4/5dAbbqpamYpU3BkXA2BcNfE200/K
CiLXWTT8oryvo22KXnjajWsQ96mNYetAbYtxPtk=
X-Google-Smtp-Source: ABdhPJxmuwkQtNwNYKYn2kKgONxdljQL6Vb8yIzWNRBQ1XEF/0cFpfSr1XeO4cmIapigMIfQp8/dlRmY4DenH01oE5w=
X-Received: by 2002:a67:441:: with SMTP id 62mr20820393vse.54.1629585332656;
Sat, 21 Aug 2021 15:35:32 -0700 (PDT)
In-Reply-To: <CAPTjJmpy7-KFyq-upY2J=scJBq32MeYMPQM0tDkZEJBgnrmKaQ@mail.gmail.com>
X-Content-Filtered-By: Mailman/MimeDel 2.1.34
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
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: <https://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>
X-Mailman-Original-Message-ID: <CAGGBd_rA=6EQJCZs63uCg37h1i9RogbhaeFg3C=viFRpxMHKhg@mail.gmail.com>
X-Mailman-Original-References: <CAGGBd_qevXB-gk2AfhjJKt-hABaQSs+x3Bo2okNqN2+Go=hrfQ@mail.gmail.com>
<11811693.O9o76ZdvQC@varric.chelsea.private>
<CAPTjJmpy7-KFyq-upY2J=scJBq32MeYMPQM0tDkZEJBgnrmKaQ@mail.gmail.com>
 by: Dan Stromberg - Sat, 21 Aug 2021 22:35 UTC

On Tue, Aug 17, 2021 at 11:20 AM Chris Angelico <rosuav@gmail.com> wrote:

> The main advantage of ast.parse() is that it no longer cares about
> code layout, and it won't be fooled by an import statement inside a
> docstring, or anything like that. It's also pretty easy to handle
> multiple variants (note how "import bar, baz" just has two things in
> the names list).
>

I put together something to detect importcycles using the ast module. It's
at https://stromberg.dnsalias.org/svn/cycles/trunk for now - no pypi, no
homepage. I've only run it on some test inputs, nothing substantial.
Usage example is in the Makefile.

Imports are kind of complicated. Am I missing any important cases?

Sample output looks like:
Detected 2 cycles:
('mutual_1', 'mutual_2')
('directory.mutual_a', 'directory.mutual_b', 'directory.mutual_c')

Thanks!

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor