Detecting circular imports

后端 未结 4 1205
情歌与酒
情歌与酒 2021-01-01 15:01

I\'m working with a project that contains about 30 unique modules. It wasn\'t designed too well, so it\'s common that I create circular imports when adding some new function

4条回答
  •  礼貌的吻别
    2021-01-01 15:16

    Not all circular imports are a problem, as you've found when an exception is not thrown.

    When they are a problem, you'll get an exception the next time you try to run any of your tests. You can change the code when this happens.

    I don't see any change required from this situation.

    Example of when it's not a problem:

    a.py

    import b
    a = 42
    def f():
      return b.b
    

    b.py

    import a
    b = 42
    def f():
      return a.a
    

提交回复
热议问题