Uploaded image for project: 'Qpid'
  1. Qpid
  2. QPID-8632

[python client] Circular imports in mllib and qpid.connection, qpid.delegates

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Blocker
    • Resolution: Fixed
    • qpid-python-1.38.0
    • qpid-python-1.38.0
    • Python Client
    • None

    Description

      Circular imports in Python actually do work, and break only when one makes a change that trips this potential minefield. One such change is Python 2/3 compatibility.

      What triggers the problem is the situation when two modules import each other, and the other module needs to be evaluated for the first import (when evaluating the first module) to complete. See https://stackoverflow.com/questions/744373/what-happens-when-using-mutual-or-circular-cyclic-imports for discussion and examples.

      Picking solution that is compatible with Python 2 as well as Python 3 in the future (QPID-8631) is tricky.

      Traceback (most recent call last):
        File "./qpid-python-test", line 29, in <module>
          from qpid.harness import Skipped
        File "/home/runner/work/qpid-python/qpid-python/qpid/__init__.py", line 20, in <module>
          from . import connection
        File "/home/runner/work/qpid-python/qpid-python/qpid/connection.py", line 29, in <module>
          from . import delegates
        File "/home/runner/work/qpid-python/qpid-python/qpid/delegates.py", line 21, in <module>
          from . import connection, session
      ImportError: cannot import name connection
      
      Traceback (most recent call last):
        File "./qpid-python-test", line 30, in <module>
          from qpid.harness import Skipped
        File "/home/runner/work/qpid-python/qpid-python/qpid/__init__.py", line 21, in <module>
          from . import connection
        File "/home/runner/work/qpid-python/qpid-python/qpid/connection.py", line 21, in <module>
          from . import datatypes, session
        File "/home/runner/work/qpid-python/qpid-python/qpid/session.py", line 22, in <module>
          from .generator import command_invoker
        File "/home/runner/work/qpid-python/qpid-python/qpid/generator.py", line 23, in <module>
          from .ops import *
        File "/home/runner/work/qpid-python/qpid-python/qpid/ops.py", line 21, in <module>
          import os, mllib, sys
        File "/home/runner/work/qpid-python/qpid-python/mllib/__init__.py", line 27, in <module>
          from . import dom, transforms, parsers
        File "/home/runner/work/qpid-python/qpid-python/mllib/dom.py", line 34, in <module>
          from . import transforms
        File "/home/runner/work/qpid-python/qpid-python/mllib/transforms.py", line 25, in <module>
          from . import dom
      ImportError: cannot import name dom
      

      Attachments

        Activity

          People

            jdanek Jiri Daněk
            jdanek Jiri Daněk
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: