Dimitrius
Dimitrius

Reputation: 786

What's new in python 3.7 about circular imports?

This is a point from python 3.7 changelog.

bpo-30024: Circular imports involving absolute imports with binding a submodule to a name are now supported.

What is the example of code that wouldn't work in 3.6 but works now?

Upvotes: 2

Views: 773

Answers (1)

Terry Jan Reedy
Terry Jan Reedy

Reputation: 19144

Issue 30024 discusses the problem and the patch. But I did not find it immediately helpful. It does mention that getting a proper, comprehensible test example would be a major step.

The patch added the following:

In Lib/test/test_import/data/circular_imports/binding.py:

import test.test_import.data.circular_imports.binding2 as binding2

In Lib/test/test_import/data/circular_imports/binding2.py:

import test.test_import.data.circular_imports.binding as binding

Two submodules of a module import each other as some name. Here is the test that presumably failed before:

def test_binding(self):
    try:
        import test.test_import.data.circular_imports.binding
    except ImportError:
        self.fail('circular import with binding a submodule to a name failed')

Upvotes: 5

Related Questions