Cyclic imports
Dan Stromberg
drsalists at gmail.com
Sat Aug 21 18:35:21 EDT 2021
On Tue, Aug 17, 2021 at 11:20 AM Chris Angelico <rosuav at 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!
More information about the Python-list
mailing list