Imports and cyclical dependencies

B

Brendan Abel

I have a relatively large python package that has several cyclical dependencies. The cyclical dependencies typically aren't a problem so long as I'm just importing modules, and not named attributes (ie. function, class, globals), which may not be defined at a given point in the import routine because of the cyclical dependency.

The problem I'm encountering is that relative imports and any import that uses the "from package import module" or "import package.module as module" syntax results in an ImportError (or AttributeError for the "as" syntax). I would much rather use this import syntax for several reasons:

1. Relative imports seem to be the recommended syntax going forward for intra-package imports.
2. One of the two import syntaxes that work does not work in Python3, or ifabsolute imports are used in Python2.
3. Imports with nested subpackages are wordy (eg. package.packa.packb.module) and make the code longer and harder to read.

I posted the question to stackoverflow with an example and got some useful information, but not the answer I was looking for.

http://stackoverflow.com/questions/19822281/why-do-these-python-import-statements-behave-differently

At this point, I'm wondering if I should report this as a bug/feature request, since it seems that these imports should be able to resolve to the correct module.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top